pytorch dataload 出錯:: invalid argument 0: Sizes of tensors must match except in dimension 0

錯誤信息:”RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 299 and 252 in dimension 3 at /pytorch/aten/src/TH/generic/THTensor.cpp:714

錯誤地方原代碼:

transforms.Resize(224) 

官方解釋:

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)

也就是如果說寫成以上的形式:

假若一個圖片大小爲(256,225)

滿足h>w,那麼圖片將放縮到(224*256/225,224),也就是並沒有放縮到我們想要的(224,224)

解決辦法:

transforms.Resize((224,224)) 就行

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章