PyTorch_YOLOv4
PyTorch_YOLOv4 copied to clipboard
List index out of range for custom annotations.
File "pytorch_yolov4/train.py", line 677, in <module>
train(hyp, opt, device, tb_writer)
File "pytorch_yolov4/train.py", line 442, in train
results, maps, times = test.test(
File "pytorch_yolov4/test.py", line 206, in test
python-BaseException
plot_images(img, output_to_target(output, width, height), paths, str(f), names) # predictions
File "/home/lfxie/tmp/pycharm_project_9/utils/general.py", line 1042, in plot_images
cls = names[cls] if names else cls
IndexError: list index out of range
I trained yolov4_tiny with my own custom annotations. And for my dataset, the nc (number of classes) is only 1. The I run python train.py. It showed this error.
Meanwhile, avoiding this occured from my annotations. I change the annotations of coco128 to other total nc, such as 1. This error happened again. I did not locate the reason of this error. Seems that it because the output of moel in line 119 in test.py is not correct. The function output_to_target() returns lables excessing the range of nc. I have only 1 classes, but it return a 40 label.
I have the same problem. Have you solved it?
Not yet, I have checked the non_max_suppression function and other called function by output_to_target(). It seems no problem about the model part and the use of inf_out. But I found a strange thing about img from testdataloader in line 108 of test.py. The values are same in one batch.
Meanwhile I run python test.py with a pretrained weights, this error happend again. I doubt it's caused by dataload.
I deleted that place, but I don't know why ’list index out of range‘
I meet the same error
Traceback (most recent call last):
File "train.py", line 438, in
I deleted that place, but I don't know why ’list index out of range‘ I deleted that place. However,3 epoch,File "train.py", line 438, in
train(hyp, opt, device, tb_writer) File "train.py", line 308, in train save_dir=log_dir) File "/home/w/文档/PyTorch_YOLOv4/test.py", line 128, in test output = non_max_suppression(inf_out, conf_thres=conf_thres, iou_thres=iou_thres, merge=merge) File "/home/w/文档/PyTorch_YOLOv4/utils/general.py", line 619, in non_max_suppression i = torchvision.ops.boxes.nms(boxes, scores, iou_thres) File "/home/w/anaconda3/envs/yolo/lib/python3.7/site-packages/torchvision/ops/boxes.py", line 36, in nms return torch.ops.torchvision.nms(boxes, scores, iou_threshold) RuntimeError: Trying to create tensor with negative dimension -1985191696: [-1985191696] RuntimeError: Trying to create tensor with negative dimension -1985191696: [-1985191696]
Using custom dataset, you need to modify classes and filters in your .cfg file. It seems the original one is for COCO dataset.
If you do not, your model will predict 80 classes, so IndexError occurs.
Original .cfg file:
[convolutional]
filters = 255
...
[yolo]
classes = 80
Your .cfg file:
[convolutional]
filters = [(4+1+classes)*3]
...
[yolo]
classes = [your class number]
And the filters in [convolutional] only above [yolo] things should be modified.
https://github.com/WongKinYiu/PyTorch_YOLOv4/blob/eb5f1663ed0743660b8aa749a43f35f505baa325/train.py#L212
Got the same error and I fix classes and filters in .cfg. Can I replace 80 with len(names) in this line? Thanks.