Hi Everyone,
I am trying to train on my own data. However, i keep getting this RuntimeError everytime i try to load my images.
It loads around 12 images and then it errors out. I made sure that my images are RGB, however, they have different sizes.
Can anyone help please?
Could you post your error message?
Thank you for your response.
Here is the error message:
Namespace(batch_size=8, checkpoint_interval=1, checkpoint_model='weights/yolov3-tiny.weights', class_path='data/fish-obj.names', compute_map='True', data_config_path='data/fish-obj.data', epochs=100, gradient_accumulations=2, img_size=416, model_config_path='data/fish-yolov3-tiny.cfg', multi_scale_training=True, n_cpu=8)
data/obj/VPS_CAM37/Lethrinus/VPS_CAM37_50350.jpg
data/obj/VPS_CAM43/Lutjanus/VPS_CAM43_5645.jpg
data/obj/VPS_CAM37/Lutjanus/VPS_CAM37_69390.jpg
data/obj/VPS_CAM33/Lethrinus/VPS_CAM33_25950.jpg
data/obj/VPS_CAM35/Lutjanus/VPS_CAM35_2225.jpg
data/obj/VPS_CAM45/Plectropomus/VPS_CAM45_4250.jpg
.
.
.
(More data)
**Traceback (most recent call last):
File "train.py", line 109, in <module>
loss, outputs = model(imgs, targets)
File "/home/fatanifh/miniconda3/envs/tensorflow_gpuenv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
result = self.forward(*input, **kwargs)
File "/home/fatanifh/YOLOv3/models.py", line 268, in forward
yolo_outputs = to_cpu(torch.cat(yolo_outputs, 1))
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 85 and 8 in dimension 2 at /opt/conda/conda-bld/pytorch_1550796191843/work/aten/src/THC/generic/THCTensorMath.cu:83**
Could you add print(imgs.shape, targets.shape) on this line, and post the output?
Every time i run it i get different sizes for example the following is three different runs:
torch.Size([1, 3, 512, 512]) torch.Size([1, 6])
torch.Size([1, 3, 352, 352]) torch.Size([1, 6])
torch.Size([1, 3, 480, 480]) torch.Size([1, 6])
Note that my batch size is 1 just for debugging.
Nothing strange about those shapes. Since we run multi-scale training the images will be reshaped to different shapes almost every run. Are you running the latest version? If not try git pull and run again and see if that fixes it.
Hi Erik,
I have tried that but i still get the same error.
Namespace(batch_size=1, checkpoint_interval=1, checkpoint_model='weights/yolov3-tiny.weights', class_path='data/fish-obj.names', compute_map='True', data_config_path='data/fish-obj.data', epochs=100, gradient_accumulations=2, img_size=416, model_config_path='data/fish-yolov3-tiny.cfg', multi_scale_training=True, n_cpu=8)
torch.Size([1, 3, 448, 448]) torch.Size([1, 6])
Traceback (most recent call last):
File "train.py", line 109, in <module>
loss, outputs = model(imgs, targets)
File "/home/fatanifh/miniconda3/envs/tensorflow_gpuenv/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
result = self.forward(*input, **kwargs)
File "/home/fatanifh/YOLOv3/models.py", line 268, in forward
yolo_outputs = to_cpu(torch.cat(yolo_outputs, 1))
RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 85 and 8 in dimension 2 at /opt/conda/conda-bld/pytorch_1550796191843/work/aten/src/THC/generic/THCTensorMath.cu:83
Seems like there is something wrong with your labels?
Do you only have one label for each image?
Yes I have one label per image.
Note that i am training
You are using your own dataset. My guess is you changed the number of classes within the yolo config file.
Make sure you change the number of classes on the multiple YOLO layers, not just one of them.
I have added instructions for how to train on a custom dataset here, could you try following those steps and see if that helps?
@eriklindernoren hi ,eriklindernoren.can you tell me how to train on a custom dataset with yolo-tiny.i modify the classes in yolov3-tiny.cfg. I appeared RuntimeError: shape '[2, 3, 7, 14, 14]' is invalid for input of size 99960.
@eriklindernoren hi ,eriklindernoren.can you tell me how to train on a custom dataset with yolo-tiny.i modify the classes in yolov3-tiny.cfg. I appeared RuntimeError: shape '[2, 3, 7, 14, 14]' is invalid for input of size 99960.
I have the same problem, how to generate custom tiny-yolo config file?
You could try yolov3-1cls.cfg file when training. It works for me.
I closed this issue due to inactivity. Feel free to reopen for further discussion.
Most helpful comment
You are using your own dataset. My guess is you changed the number of classes within the yolo config file.
Make sure you change the number of classes on the multiple YOLO layers, not just one of them.