-
Notifications
You must be signed in to change notification settings - Fork 143
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
RuntimeError: got 4 channels instead #9
Comments
Hi, based on the error message you've got, I think your input image file is PNG having alpha channel in addition to RGB so that the input has 4 channels. Because the model is trained on RGB three channels, it pops up the dimension mismatch error. Please try with JPG input having RGB only. (You can do this simply by using commonly used image processing packages) |
Dear Amber
All the files in your examples are .png files which work fine during my test. So what's wrong with my .png files?
Yes, that is because PNG can have 4 channels or 3 channels. Since you changed the file to jpg, now your file has 3 channels. Check this out:
https://en.wikipedia.org/wiki/Portable_Network_Graphics#Pixel_format
"The number of channels depends on whether the image is grayscale or color and whether it has an alpha channel. PNG allows the following combinations of channels, called the color type."
Now the error you are having is due to the assertion in the code at: https://github.com/clovaai/WCT2/blob/6162e29c5897ba12e946d772da006630359b35ee/transfer.py#L144-L146
If you comment out the lines where the assertion is and If you have successfully changed the file to have 3 channels, I believe the network should work fine. If you don't want to touch the code you can simply change the filename to end with '.png', then it should work fine too.
This is entirely my bad. Because every image in the benchmark datasets ended with ',png' and had only 3 channels, I did not notice that there can be such unseen cases. I will update the code to deal with such problems too.
Thank you for your constructive comments and please let me know whether your problem is solved or not. If you have any other questions, please do not hesitate to contact me.
Best,
Jaejun
2019년 7월 1일 (월) 오후 12:22, Amber Ji <notifications@github.com>님이 작성:
… @jaejun-yoo <https://github.com/jaejun-yoo>
Hi, here's the results I got after changing 1.png into 1.jpg in the
following 4 folders
./example/content/
./example/content_segment/
./example/style/
./example/style_segment/
Test the Model
!python3 transfer.py --option_unpool cat5 -a --content ./examples/content
--style ./examples/style --content_segment ./examples/content_segment
--style_segment ./examples/style_segment/ --output ./outputs/ --verbose
--image_size 1024
Namespace(alpha=1, content='./examples/content',
content_segment='./examples/content_segment', cpu=False, image_size=1024,
option_unpool='cat5', output='./outputs/', style='./examples/style',
style_segment='./examples/style_segment/', transfer_all=True,
transfer_at_decoder=False, transfer_at_encoder=False,
transfer_at_skip=False, verbose=True)
0% 0/1 [00:00<?, ?it/s]invalid file (should end with .png), 1.jpg
100% 1/1 [00:00<00:00, 2674.94it/s]
P.S. All the files in your examples are .png files which work fine during
my test. So what's wrong with my .png files?
Sincerely,
Amber
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9?email_source=notifications&email_token=ADNAIC7TLNFSSSJQUE6VEP3P5FZ73A5CNFSM4H4EMCSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY44HTQ#issuecomment-507102158>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADNAIC3NVQYW35DLYLCA6ZDP5FZ73ANCNFSM4H4EMCSA>
.
--
*JaeJun Yoo, **Ph.D. *
*------------------------------------------------------------*
NAVER Corp.Clova ML AI Research Scientist
11th Fl., NAVER Green Factory, 6, Buljeong-ro, Bundang-gu, Seongnam-si,
Gyeonggi-do, 13561, Korea
(c.p.) +82-(0)10-9442-7832
(E-mail) jaejun.yoo@navercorp.com, jaejun2004@kaist.ac.kr
修身齊家治國平天下
|
@jaejun-yoo So far, the problem is solved. Thank you! All the best, Amber |
Hi!
I followed your instruction step by step, and after typing
!python3 transfer.py --option_unpool cat5 -a --content ./examples/content --style ./examples/style --content_segment ./examples/content_segment --style_segment ./examples/style_segment/ --output ./outputs/ --verbose --image_size 512
I got
Namespace(alpha=1, content='./examples/content', content_segment='./examples/content_segment', cpu=False, image_size=512, option_unpool='cat5', output='./outputs/', style='./examples/style', style_segment='./examples/style_segment/', transfer_all=True, transfer_at_decoder=False, transfer_at_encoder=False, transfer_at_skip=False, verbose=True)
0% 0/1 [00:00<?, ?it/s]------ transfer: 1.png
Elapsed time in whole WCT: 0:00:02.926612
Traceback (most recent call last):
File "transfer.py", line 205, in
run_bulk(config)
File "transfer.py", line 175, in run_bulk
img = wct2.transfer(content, style, content_segment, style_segment, alpha=config.alpha)
File "transfer.py", line 79, in transfer
style_feats, style_skips = self.get_all_feature(style)
File "transfer.py", line 64, in get_all_feature
x = self.encode(x, skips, level)
File "transfer.py", line 55, in encode
return self.encoder.encode(x, skips, level)
File "/content/drive/WCT2/model.py", line 163, in encode
out = self.conv0(x)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/conv.py", line 338, in forward
self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size 3 3 1 1, expected input[1, 4, 512, 512] to have 3 channels, but got 4 channels instead
Could you help me please? Thank you!
Sincerely,
Amber
@jaejun-yoo
The text was updated successfully, but these errors were encountered: