sefibk / KernelGAN

Other
337 stars 77 forks source link

ValueError: shapes (512,512,1) and (3,) not aligned: 1 (dim 2) != 3 (dim 0) #81

Closed antoineDhanis closed 1 year ago

antoineDhanis commented 1 year ago

Hi, Thanks for your work!

I want to use your code with a gray image, I have the following error, could you help me ?

`Scale Factor: X2 ZSSR: True Real Image: False


STARTED KernelGAN on: "input\20170425-pt-e282204509-std-71b73cdef9-seq-8-ang-p28-n2.4-f-00015.png"... 100%|███████████████████| 3000/3000 [05:46<00:00, 11.35it/s] E:\Universite\Ma2\TFE\KernelGan\KernelGAN\results\input\20170425-pt-e282204509-std-71b73cdef9-seq-8-ang-p28-n2lllllll KernelGAN estimation complete!


Running ZSSR X2...
Traceback (most recent call last):
  File "train.py", line 55, in <module>
    main()
  File "train.py", line 37, in main
    train(conf)
  File "train.py", line 19, in train
    gan.finish()
  File "E:\Universite\Ma2\TFE\KernelGan\KernelGAN\kernelGAN.py", line 126, in finish
    run_zssr(final_kernel, self.conf)
  File "E:\Universite\Ma2\TFE\KernelGan\KernelGAN\util.py", line 230, in run_zssr
    sr = ZSSR(conf.input_image_path, scale_factor=2, kernels=[k_2], is_real_img=conf.real_image, noise_scale=conf.noise_scale).run()
  File "E:\Universite\Ma2\TFE\KernelGan\KernelGAN\ZSSRforKernelGAN\ZSSR.py", line 99, in __init__
    self.loss_map = create_loss_map(im=self.input) if self.conf.grad_based_loss_map else np.ones_like(self.input)
  File "E:\Universite\Ma2\TFE\KernelGan\KernelGAN\ZSSRforKernelGAN\zssr_utils.py", line 255, in create_loss_map
    gray = np.dot(im[:, :, 0:3], [0.299, 0.587, 0.114]) if len(im.shape) == 3 else im
ValueError: shapes (512,512,1) and (3,) not aligned: 1 (dim 2) != 3 (dim 0)`
sefibk commented 1 year ago

As the print notes - it is not an error with KernelGAN but with the ZSSR code. It might be that the ZSSR can't accept both RGB and 1-channel images. a. You can use a different work for the SR using KernelGAN's kernel b. It might be ok to duplicate the channel 3 times before running ZSSR

antoineDhanis commented 1 year ago

Thanks, I duplicated the channel before KernelGAN and everything seems to be working now.