![](/img/trans.png)
[英]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: The size of tensor a (128) must match the size of tensor b (256) at non-singleton dimension 3
請我幫助我如何在 256x256 的圖像尺寸上訓練我的模型 我更改了圖像大小,但出現了無法解決的錯誤:
文件“train_128.py”,第 149 行,在 main
g_img_rec_loss = torch.abs(img_rec - imgs).mean()
RuntimeError:張量 a (128) 的大小必須與非單維 3 的張量 b (256) 的大小相匹配
代碼來源是: https ://github.com/biswassanket/synth_doc_generation
提前致謝
發生錯誤是因為您的變量img_rec
是 size (batch_size, 3, 128, 128) 而另一個變量imgs
是 size (batch_size, 3, 256, 256)。
如果您從 dataLoader 傳遞 256 * 256 圖像,您還需要確保生成 256 * 256 圖像,而您沒有這樣做。
在這行代碼中。 當您進行輸出時,您將獲得 128 * 128 的圖像,因此您可能需要更改 netG 中的參數或調整輸出大小。
希望這可以幫助
SanrthakJain:我檢查了代表生成器模型的 netG https://github.com/biswassanket/synth_doc_generation/blob/main/layout2im/models/generator_128.py
你能指導我應該做哪些修改來修復這個錯誤嗎?
提前致謝。
謝謝你的問題我遇到了同樣的問題,請 SarthakJain 你能與我們分享如何調整輸出大小來解決這個問題嗎?
對像我這樣的初學者的幫助表示贊賞
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.