pytorch dataloader 取batch_size時(shí)候出現(xiàn)bug的解決方式
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來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 問題
解決2:
也可以直接用opencv resize
以上這篇pytorch dataloader 取batch_size時(shí)候出現(xiàn)bug的解決方式就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python連接SQLite數(shù)據(jù)庫并進(jìn)行增冊(cè)改查操作方法詳解
這篇文章主要介紹了Python對(duì)SQLite數(shù)據(jù)庫進(jìn)行增冊(cè)改查操作方法詳解,需要的朋友可以參考下2020-02-02使用python爬取連續(xù)降水?dāng)?shù)據(jù)信息實(shí)例
這篇文章主要為大家介紹了使用python提取連續(xù)降水?dāng)?shù)據(jù)信息實(shí)現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01python程序中的線程操作 concurrent模塊使用詳解
這篇文章主要介紹了python程序中的線程操作 concurrent模塊使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-09-09linux之父進(jìn)程使用kill函數(shù)殺死子進(jìn)程方式
這篇文章主要介紹了linux之父進(jìn)程使用kill函數(shù)殺死子進(jìn)程方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06