简体   繁体   English

RuntimeError:张量 a (128) 的大小必须与非单维 3 的张量 b (256) 的大小相匹配

[英]RuntimeError: The size of tensor a (128) must match the size of tensor b (256) at non-singleton dimension 3

Please I need your help on how I can train my model on image dimension of 256x256 I changed the image size but I got this error that I couldn't solve it :请我帮助我如何在 256x256 的图像尺寸上训练我的模型 我更改了图像大小,但出现了无法解决的错误:

File "train_128.py", line 149, in main文件“train_128.py”,第 149 行,在 main
g_img_rec_loss = torch.abs(img_rec - imgs).mean() g_img_rec_loss = torch.abs(img_rec - imgs).m​​ean()
RuntimeError: The size of tensor a (128) must match the size of tensor b (256) at non-singleton dimension 3 RuntimeError:张量 a (128) 的大小必须与非单维 3 的张量 b (256) 的大小相匹配

The code source is : https://github.com/biswassanket/synth_doc_generation代码来源是: https ://github.com/biswassanket/synth_doc_generation

thanks in advance提前致谢

The error is happening because your variable img_rec is size (batch_size, 3, 128, 128) and the other variable imgs is size (batch_size, 3, 256, 256).发生错误是因为您的变量img_rec是 size (batch_size, 3, 128, 128) 而另一个变量imgs是 size (batch_size, 3, 256, 256)。

If you are passing 256 * 256 images from your dataLoader you also need to make sure you are generating 256 * 256 images which you are not doing.如果您从 dataLoader 传递 256 * 256 图像,您还需要确保生成 256 * 256 图像,而您没有这样做。

Over here in this line of code .在这行代码中。 When you make the output you are getting a 128 * 128 image so you may need to change the params in netG or do a resize on the output.当您进行输出时,您将获得 128 * 128 的图像,因此您可能需要更改 netG 中的参数或调整输出大小。

Hope this helps希望这可以帮助

SanrthakJain: I checked the netG which is stand for the generator model https://github.com/biswassanket/synth_doc_generation/blob/main/layout2im/models/generator_128.py SanrthakJain:我检查了代表生成器模型的 netG https://github.com/biswassanket/synth_doc_generation/blob/main/layout2im/models/generator_128.py

could you please guide me which modification I should do to fix this error?你能指导我应该做哪些修改来修复这个错误吗?

thanks in advance.提前致谢。

Thank you for your question I face the same problem please SarthakJain could you share with us how to resize in the output to solve this problem?谢谢你的问题我遇到了同样的问题,请 SarthakJain 你能与我们分享如何调整输出大小来解决这个问题吗?

Help appreciated for a beginner like me对像我这样的初学者的帮助表示赞赏

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对于 SNN,如何解决`RuntimeError:张量 a (3) 的大小必须与非单维 1 的张量 b (128) 的大小相匹配? - How to resolve `RuntimeError: The size of tensor a (3) must match the size of tensor b (128) at non-singleton dimension 1` for SNN? RuntimeError:张量 a (4000) 的大小必须与非单维 1 的张量 b (512) 的大小相匹配 - RuntimeError: The size of tensor a (4000) must match the size of tensor b (512) at non-singleton dimension 1 RuntimeError:张量 a (38) 的大小必须与非单维 3 处的张量 b (34) 的大小相匹配 - RuntimeError: The size of tensor a (38) must match the size of tensor b (34) at non-singleton dimension 3 PyTorch:RuntimeError:张量 a (224) 的大小必须与非单维 3 的张量 b (244) 的大小相匹配 - PyTorch: RuntimeError: The size of tensor a (224) must match the size of tensor b (244) at non-singleton dimension 3 运行时错误:张量 a (1024) 的大小必须与非单维 3 处的张量 b (512) 的大小匹配 - RuntimeError: The size of tensor a (1024) must match the size of tensor b (512) at non-singleton dimension 3 Pytorch RuntimeError:张量 a (4) 的大小必须与非单维 0 处的张量 b (3) 的大小相匹配 - Pytorch RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0 训练 CNN 时出错:“RuntimeError:张量 a (10) 的大小必须与非单维 1 的张量 b (64) 的大小相匹配” - Error when training CNN: "RuntimeError: The size of tensor a (10) must match the size of tensor b (64) at non-singleton dimension 1" Pytorch 迁移学习错误:张量 a (16) 的大小必须与非单维 2 的张量 b (128) 的大小匹配 - Pytorch transfer learning error: The size of tensor a (16) must match the size of tensor b (128) at non-singleton dimension 2 张量 a (707) 的大小必须与非单维 1 处的张量 b (512) 的大小相匹配 - The size of tensor a (707) must match the size of tensor b (512) at non-singleton dimension 1 错误:张量 a (892) 的大小必须与非单维 3 的张量 b (400) 的大小相匹配 - Error: The size of tensor a (892) must match the size of tensor b (400) at non-singleton dimension 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM