RuntimeError: 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 337 and 336 in dimension 3 at /opt/conda/conda-bld/pytorch_1565272279342/work/aten/src/TH/generic/THTensor.cpp:689
解決方法:
這是因爲輸入的大小不匹配,跟數據集有關,也跟數據預處理中的函數相關:
transforms.Resize(input_size)
該函數是按比例縮放,可能是因爲該數據集的分辨率不同,所以出來的結果不是(224,224)的,解決辦法是改爲使用:
transforms.Resize((input_size, input_size))
即可
參考資料:
1 pytorch數據預處理錯誤的解決