KupynOrest / DeblurGAN

Image Deblurring using Generative Adversarial Networks
Other
2.5k stars 516 forks source link

Grayscale images #61

Open bionictoucan opened 6 years ago

bionictoucan commented 6 years ago

I am trying to train the network with grayscale images and I'm having some trouble. I am trying to use an unaligned dataset with the blurry and sharp images in different directories. When I just try to run the network with the --input_nc and --output_nc options both being 1 I get the error Traceback (most recent call last): File "train.py", line 58, in <module> train(opt, data_loader, model, visualizer) File "train.py", line 21, in train model.optimize_parameters() File "/home/armstrong/DeblurGAN-master/models/conditional_gan_model.py", line 104, in optimize_parameters self.forward() File "/home/armstrong/DeblurGAN-master/models/conditional_gan_model.py", line 76, in forward self.fake_B = self.netG.forward(self.real_A) File "/home/armstrong/DeblurGAN-master/models/networks.py", line 146, in forward output = self.model(input) File "/usr/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__ result = self.forward(*input, **kwargs) File "/usr/lib64/python3.6/site-packages/torch/nn/modules/container.py", line 67, in forward input = module(input) File "/usr/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__ result = self.forward(*input, **kwargs) File "/usr/lib64/python3.6/site-packages/torch/nn/modules/conv.py", line 282, in forward self.padding, self.dilation, self.groups) File "/usr/lib64/python3.6/site-packages/torch/nn/functional.py", line 90, in conv2d return f(input, weight, bias) RuntimeError: Given groups=1, weight[64, 1, 7, 7], so expected input[1, 3, 262, 262] to have 1 channels, but got 3 channels instead so I tried to edit the unaligned_dataset.py to change lines 32 and 33 so that the convert argument is now "L", but that then results in the error message Traceback (most recent call last): File "train.py", line 58, in <module> train(opt, data_loader, model, visualizer) File "train.py", line 21, in train model.optimize_parameters() File "/home/armstrong/DeblurGAN-master/models/conditional_gan_model.py", line 112, in optimize_parameters self.backward_G() File "/home/armstrong/DeblurGAN-master/models/conditional_gan_model.py", line 97, in backward_G self.loss_G_Content = self.contentLoss.get_loss(self.fake_B, self.real_B) * self.opt.lambda_A File "/home/armstrong/DeblurGAN-master/models/losses.py", line 41, in get_loss f_fake = self.contentFunc.forward(fakeIm) File "/usr/lib64/python3.6/site-packages/torch/nn/modules/container.py", line 67, in forward input = module(input) File "/usr/lib64/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__ result = self.forward(*input, **kwargs) File "/usr/lib64/python3.6/site-packages/torch/nn/modules/conv.py", line 282, in forward self.padding, self.dilation, self.groups) File "/usr/lib64/python3.6/site-packages/torch/nn/functional.py", line 90, in conv2d return f(input, weight, bias) RuntimeError: Given groups=1, weight[64, 3, 3, 3], so expected input[1, 1, 256, 256] to have 3 channels, but got 1 channels instead I was wondering if you've tried training with grayscale images and if you could help?

I also had an issue trying to make an aligned dataset wherein the resulting images after using the combine A and B code were just the images combined with itself. So rather than the image being a combination of the blur and sharp image I end up with double the amount of images where each is just either the blur or the sharp image twice. When using this code I have the --foldA as a link to the blurry images and the --foldB as a link to the sharp images, is this the right thing to do?

Thanks for your help.

KupynOrest commented 6 years ago

Hello, we didn't try to train the model with grayscale images. The problem is that we use loss function based on VGG activation maps and VGG net was pretrained on RGB images from ImageNet dataset. One think you could do is simply to convert grayscale images to calculate perceptual loss.