Python Forum
labels.append(self.classes.index(member.find('name').text)) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: labels.append(self.classes.index(member.find('name').text)) (/thread-35794.html)



labels.append(self.classes.index(member.find('name').text)) - hobbyist - Dec-15-2021

Hello, I am following this tutorial: tutorial in order to train my custom object detector model. I have followed what the guy says. However, when I try to execute the code, with the command that he suggests

python engine.py
I get the below error which I cannot understand how to handle it...

Error:
File "/home/UbuntuUser/Desktop/Custom_Object_Detection_using_PyTorch_Faster_RCNN/datasets.py", line 52, in __getitem__ labels.append(self.classes.index(member.find('name').text)) ValueError: 'car_001' is not in list
The code in the above link is the datasets.py and part of the code that hits error is depicted below:

       
. . .
        # box coordinates for xml files are extracted and corrected for image size given
        for member in root.findall('object'):
            # map the current object name to `classes` list to get...
            # ... the label index and append to `labels` list
            labels.append(self.classes.index(member.find('name').text))
            
            # xmin = left corner x-coordinates
            xmin = int(member.find('bndbox').find('xmin').text)
            # xmax = right corner x-coordinates
            xmax = int(member.find('bndbox').find('xmax').text)
            # ymin = left corner y-coordinates
            ymin = int(member.find('bndbox').find('ymin').text)
            # ymax = right corner y-coordinates
            ymax = int(member.find('bndbox').find('ymax').text)
            
            # resize the bounding boxes according to the...
            # ... desired `width`, `height`
            xmin_final = (xmin/image_width)*self.width
            xmax_final = (xmax/image_width)*self.width
            ymin_final = (ymin/image_height)*self.height
            yamx_final = (ymax/image_height)*self.height
            
            boxes.append([xmin_final, ymin_final, xmax_final, yamx_final])
. . .
Any ideas???

Update: I copied-pasted it right this time....

Any help??


RE: labels.append(self.classes.index(member.find('name').text)) - deanhystad - Dec-15-2021

Indenting is wrong. The for loop has no body.