溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

pytorch dataloader 取batch_size時(shí)候出現(xiàn)bug的解決方式

發(fā)布時(shí)間:2020-10-09 12:34:52 來(lái)源:腳本之家 閱讀:277 作者:U_C 欄目:開發(fā)技術(shù)

1、

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 342 and 281 in dimension 3 at /pytorch/aten/src/TH/generic/THTensorMoreMath.cpp:1333

2、

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 3 and 1 in dimension 1

bug1 修改方法是將圖片resize 成一個(gè)尺度: 

解決1:

如果用transforms來(lái)resize ,關(guān)于尺寸的transform就是transforms.Resize(input_size, interpolation=3)了。

查看Resize的文檔:

size (sequence or int) – Desired output size. If size is a sequence like (h, w), output size will be matched to this.

If size is an int, smaller edge of the image will be matched to this number. i.e, if height > width, then image will be rescaled to (size * height / width, size)

size這個(gè)參數(shù)既可以是一個(gè)數(shù)字,又可以是一個(gè)tuple,如果是數(shù)字,圖片處理后的輸出尺寸每次都會(huì)被重新計(jì)算為(input_size*height/width, size),這樣如果輸入圖片尺寸不一致,輸出圖片尺寸會(huì)不一致, 將導(dǎo)致bug1 問(wèn)題

解決2:

也可以直接用opencv resize

以上這篇pytorch dataloader 取batch_size時(shí)候出現(xiàn)bug的解決方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持億速云。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI