Po-Hsun-Su / pytorch-ssim

pytorch structural similarity (SSIM) loss
Other
1.89k stars 367 forks source link

I visualize the img2 in max_ssim.py, but it is not the gif shown in the home page. what mistake do I make? The following is the code, modified in max_ssim.py. #22

Open THHHomas opened 5 years ago

THHHomas commented 5 years ago

while ssim_value < 0.95: optimizer.zero_grad() ssim_out = -ssim_loss(img1, img2) ssim_value = - ssim_out.item() print(ssim_value) ssim_out.backward() optimizer.step() ii = np.transpose(img2[0].detach().cpu().numpy(), (1,2,0)) cv2.imshow("pre", ii255) print(np.max(ii255)) cv2.waitKey(100)

bornabesic commented 5 years ago

You haven't explained what kind of results you get, but I guess you are looking at a noisy white image. After you multiply the array by 255 you also need to convert it to a byte type.

cv2.imshow("pre", (ii * 255).astype(np.uint8))