Python Forum
labels.append(self.classes.index(member.find('name').text))
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
labels.append(self.classes.index(member.find('name').text))
#1
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??
Reply
#2
Indenting is wrong. The for loop has no body.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Class member become static Quasar999 1 683 Sep-16-2023, 12:52 PM
Last Post: deanhystad
  Pypdf2 will not find text standenman 2 947 Feb-03-2023, 10:52 PM
Last Post: standenman
  [SOLVED] [Beautifulsoup] Find if element exists, and edit/append? Winfried 2 4,317 Sep-03-2022, 10:14 PM
Last Post: Winfried
  read a text file, find all integers, append to list oldtrafford 12 3,619 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  find some word in text list file and a bit change to them RolanRoll 3 1,550 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  Find and delete above a certain line in text file cubangt 12 3,512 Mar-18-2022, 07:49 PM
Last Post: snippsat
  How to find tags using specific text (timestamps) in a url? q988988 1 1,387 Mar-08-2022, 08:09 AM
Last Post: buran
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,323 Oct-23-2021, 04:35 AM
Last Post: JaneTan
Thumbs Up [SOLVED] Find last occurence of pattern in text file? Winfried 4 4,428 Aug-13-2021, 08:21 PM
Last Post: Winfried
  How to define a variable in Python that points to or is a reference to a list member JeffDelmas 4 2,666 Feb-28-2021, 10:38 PM
Last Post: JeffDelmas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020