-
Notifications
You must be signed in to change notification settings - Fork 19
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: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0 #1
Comments
It seems that the channel of img is 4 (RGBA), which is expected to be 3 (RGB). If your result is (256, 256, 4), you need to convert it to RGB first. |
Well, thank you very much.I found a solution on Baidu.But now there is another problem. All my documents are shown in the attachment. The program ran for a long time without results. I don't know if this is normal.
…------------------ 原始邮件 ------------------
发件人: "StoryMY/take-off-eyeglasses" ***@***.***>;
发送时间: 2022年5月10日(星期二) 下午5:22
***@***.***>;
***@***.******@***.***>;
主题: Re: [StoryMY/take-off-eyeglasses] RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0 (Issue #1)
It seems that the channel of img is 4 (RGBA), which is expected to be 3 (RGB).
You can print(img.shape) before "img = transform(img)" to check it.
The correct shape is expected to be torch.Size([3, 256, 256]).
If your result is torch.Size([4, 256, 256]), you need to convert it to RGB first.
Maybe like this: "img = Image.open(os.path.join(args.input_dir, img_name)).convert('RGB')" (Line 64)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sorry, there is something wrong with my configuration environment
…------------------ 原始邮件 ------------------
发件人: "StoryMY/take-off-eyeglasses" ***@***.***>;
发送时间: 2022年5月10日(星期二) 下午5:22
***@***.***>;
***@***.******@***.***>;
主题: Re: [StoryMY/take-off-eyeglasses] RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0 (Issue #1)
It seems that the channel of img is 4 (RGBA), which is expected to be 3 (RGB).
You can print(img.shape) before "img = transform(img)" to check it.
The correct shape is expected to be torch.Size([3, 256, 256]).
If your result is torch.Size([4, 256, 256]), you need to convert it to RGB first.
Maybe like this: "img = Image.open(os.path.join(args.input_dir, img_name)).convert('RGB')" (Line 64)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你好,我想问一下,为什么会出现这个问题呀?
Hello, I'd like to ask, why is this problem?
Traceback (most recent call last):
File "easy_use.py", line 97, in
generate_results(args, device)
File "easy_use.py", line 66, in generate_results
img = transform(img)
File "/disk/sdb/public_user/anaconda3/envs/wxy_env/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 67, in call
img = t(img)
File "/disk/sdb/public_user/anaconda3/envs/wxy_env/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in call_impl
result = self.forward(*input, **kwargs)
File "/disk/sdb/public_user/anaconda3/envs/wxy_env/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 226, in forward
return F.normalize(tensor, self.mean, self.std, self.inplace)
File "/disk/sdb/public_user/anaconda3/envs/wxy_env/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 284, in normalize
tensor.sub(mean).div_(std)
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0
The text was updated successfully, but these errors were encountered: