pytorch-yolo-v3
pytorch-yolo-v3 copied to clipboard
Error by running YOLOv3 with one class
Hi everyone,
I already have a Cfg-file and weight file for YOLOv3, which I got with Darknet-Framework after the successful training with one class. I wanted to use these files to analyze the performance of Pytorch. Unfortunately, the running of YOLOv3 failed and I got the following error message:
(env) C:\Users\n01pham\Desktop\Data2Day\pytorch-yolo-v3-master>python detect.py --cfg cfg/yolov3_3l.cfg --weights yolov3_3l.weights --images imgs/Berlin.jpg
Loading network.....
Network successfully loaded
C:\ProgramData\Anaconda3\envs\env\lib\site-packages\torch\nn\modules\upsampling.py:129: UserWarning: nn.Upsample is deprecated. Use nn.functional.interpolate instead.
warnings.warn("nn.{} is deprecated. Use nn.functional.interpolate instead.".format(self.name))
Traceback (most recent call last):
File "detect.py", line 242, in <module>
objs = [classes[int(x[-1])] for x in output if int(x[0]) == im_id]
File "detect.py", line 242, in <listcomp>
objs = [classes[int(x[-1])] for x in output if int(x[0]) == im_id]
IndexError: list index out of range
In the detect.py I set the number of classes in 112th line to 1. I also changed the list of class names in the voc.names file to the name of my class. I'd be very happy if you could help me with that.
Best regards
The problem is at line 80 of util.py.
If you only have one class, the load_class function at util.py will return an empty list instead of a list with one item. It can be fixed by replacing the load_class function in util.py (line 212) with:
def load_classes(namesfile): fp = open(namesfile, "r") names = [i.strip('\n') for i in fp.readlines()] return names
Thanks @TiongSun for your response it actually resolved this error for me!