Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot input grayscale images #92

Closed
gvenkat21 opened this issue Dec 13, 2018 · 7 comments
Closed

Cannot input grayscale images #92

gvenkat21 opened this issue Dec 13, 2018 · 7 comments

Comments

@gvenkat21
Copy link

Hi,

I have a folder of grayscale images that I want to use for training. I am using the following command:

python train.py --dataroot ./datasets/sample --name sample --loadSize 1536 --fineSize 512 --no_flip --batchSize 3 --niter 3000 --gpu_ids 1 --no_instance --resize_or_crop resize_and_crop --label_nc 0 --n_local_enhancers 1 --norm batch --use_dropout --input_nc 1 --output_nc 1

But I am getting the following error:

RuntimeError: Given groups=1, weight of size [64, 1, 7, 7], expected input[3, 3, 518, 518] to have 1 channels, but got 3 channels instead

What is the issue?

@leweohlsen
Copy link

Hi,

the issue is that in the DataLoader, inputs and outputs are always converted to RGB like this, even when you specify --input_nc 1 --output_nc 1.

You could remove the converting or make it conditional but RGB images seem to be required for the Vgg19 model. You could probably go with --no_vgg_loss.

Looks like we need a custom DataLoader for grayscale images?

@gvenkat21
Copy link
Author

Ok...thanks...I’ll try your suggestion

@TravisFar
Copy link

Hi, I will be very grateful if you tell how prepare your dataset as grayscale images to feed the pix2pixhd?
I am working on medical images so I have 3 modalities and I wanna synthesize another one but I dont know how I should prepare dataset for this. By preparing, I mean, creating input matrix. thank you for your time,

@WenliangDu
Copy link

Hi,

I have a folder of grayscale images that I want to use for training. I am using the following command:

python train.py --dataroot ./datasets/sample --name sample --loadSize 1536 --fineSize 512 --no_flip --batchSize 3 --niter 3000 --gpu_ids 1 --no_instance --resize_or_crop resize_and_crop --label_nc 0 --n_local_enhancers 1 --norm batch --use_dropout --input_nc 1 --output_nc 1

But I am getting the following error:

RuntimeError: Given groups=1, weight of size [64, 1, 7, 7], expected input[3, 3, 518, 518] to have 1 channels, but got 3 channels instead

What is the issue?

Hi

I solved the --input_nc 1 problem by editing the data/base_dataset.py (for transforms), data/aligned_dataset.py (for transforms) and models/pix2pixHD_model.py (for VGG loss). You can get the updated version in https://github.com/WenliangDu/pix2pixHD, and find the changes in the three codes with comments of "# for --input_nc 1"

@1999kevin
Copy link

Hi,
I have a folder of grayscale images that I want to use for training. I am using the following command:
python train.py --dataroot ./datasets/sample --name sample --loadSize 1536 --fineSize 512 --no_flip --batchSize 3 --niter 3000 --gpu_ids 1 --no_instance --resize_or_crop resize_and_crop --label_nc 0 --n_local_enhancers 1 --norm batch --use_dropout --input_nc 1 --output_nc 1
But I am getting the following error:
RuntimeError: Given groups=1, weight of size [64, 1, 7, 7], expected input[3, 3, 518, 518] to have 1 channels, but got 3 channels instead
What is the issue?

Hi

I solved the --input_nc 1 problem by editing the data/base_dataset.py (for transforms), data/aligned_dataset.py (for transforms) and models/pix2pixHD_model.py (for VGG loss). You can get the updated version in https://github.com/WenliangDu/pix2pixHD, and find the changes in the three codes with comments of "# for --input_nc 1"

Do you have any idea for input_nc 3(RGB) and output_nc 1(gray)? I have tried your code and it doesn't work.

@WenliangDu
Copy link

Hi,
I have a folder of grayscale images that I want to use for training. I am using the following command:
python train.py --dataroot ./datasets/sample --name sample --loadSize 1536 --fineSize 512 --no_flip --batchSize 3 --niter 3000 --gpu_ids 1 --no_instance --resize_or_crop resize_and_crop --label_nc 0 --n_local_enhancers 1 --norm batch --use_dropout --input_nc 1 --output_nc 1
But I am getting the following error:
RuntimeError: Given groups=1, weight of size [64, 1, 7, 7], expected input[3, 3, 518, 518] to have 1 channels, but got 3 channels instead
What is the issue?

Hi
I solved the --input_nc 1 problem by editing the data/base_dataset.py (for transforms), data/aligned_dataset.py (for transforms) and models/pix2pixHD_model.py (for VGG loss). You can get the updated version in https://github.com/WenliangDu/pix2pixHD, and find the changes in the three codes with comments of "# for --input_nc 1"

Do you have any idea for input_nc 3(RGB) and output_nc 1(gray)? I have tried your code and it doesn't work.

Thank you for pointing the bug. I modified Line 54 in aligned_dataset.py. You could try this code for your issue.

"transform_B = get_transform(self.opt, params, grayscale=(self.opt.input_nc == 1))"=>"transform_B = get_transform(self.opt, params, grayscale=(self.opt.output_nc == 1))"

@1999kevin
Copy link

Thank you very much!

Hi,

I have a folder of grayscale images that I want to use for training. I am using the following command:

python train.py --dataroot ./datasets/sample --name sample --loadSize 1536 --fineSize 512 --no_flip --batchSize 3 --niter 3000 --gpu_ids 1 --no_instance --resize_or_crop resize_and_crop --label_nc 0 --n_local_enhancers 1 --norm batch --use_dropout --input_nc 1 --output_nc 1

But I am getting the following error:

RuntimeError: Given groups=1, weight of size [64, 1, 7, 7], expected input[3, 3, 518, 518] to have 1 channels, but got 3 channels instead

What is the issue?

Hi

I solved the --input_nc 1 problem by editing the data/base_dataset.py (for transforms), data/aligned_dataset.py (for transforms) and models/pix2pixHD_model.py (for VGG loss). You can get the updated version in https://github.com/WenliangDu/pix2pixHD, and find the changes in the three codes with comments of "# for --input_nc 1"

Do you have any idea for input_nc 3(RGB) and output_nc 1(gray)? I have tried your code and it doesn't work.

Thank you for pointing the bug. I modified Line 54 in aligned_dataset.py. You could try this code for your issue.

"transform_B = get_transform(self.opt, params, grayscale=(self.opt.input_nc == 1))"=>"transform_B = get_transform(self.opt, params, grayscale=(self.opt.output_nc == 1))"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants