具體錯誤日志如下:
The resulting error log is as follows Traceback (most recent call last): File "train.py", line 441, in <module> train() # train normally File "train.py", line 324, in train dataloader=testloader) File "F:\train\yolov3hat\test.py", line 85, in test inf_out, train_out = model(imgs) # inference and training outputs File "D:\Program Files\Python\Python37\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__ result = self.forward(*input, **kwargs) File "F:\train\yolov3hat\models.py", line 260, in forward return torch.cat(io, 1), p RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 7 and 85 in dimension 2 at C:/w/1/s/windows/pytorch/aten/src\THC/generic/THCTensorMath.cu:71
解決辦法:
- 你輸入的圖像數據的維度不完全是一樣的,比如是訓練的數據有100組,其中99組是256*256,但有一組是384*384,這樣會導致Pytorch的檢查程序報錯
- 另外一個則是比較隱晦的batchsize的問題,Pytorch中檢查你訓練維度正確是按照每個batchsize的維度來檢查的,比如你有1000組數據(假設每組數據為三通道256px*256px的圖像),batchsize為4,那么每次訓練則提取(4,3,256,256)維度的張量來訓練,剛好250個epoch解決(250*4=1000)。但是如果你有999組數據,你繼續使用batchsize為4的話,這樣999和4並不能整除,你在訓練前249組時的張量維度都為(4,3,256,256)但是最后一個批次的維度為(3,3,256,256),Pytorch檢查到(4,3,256,256) != (3,3,256,256),維度不匹配,自然就會報錯了,這可以稱為一個小bug。
本次我提出的問題:
你應該檢查你的 yolov3的配置文件中 全連接層的配置情況