'Loading the bounding boxes properly for multi class object detection

I'm looking forward to detecting multiple objects which means that the output of the final layer will be based on the number of objects that is in the frame. I'm loading the labels and the image paths as follows,

 for i in range(len(bboxes)):
    bbox = bboxes[i]
    startX, startY, endX, endY = bbox

    startX = float(startX) / w
    startY = float(startY) / h
    endX = float(endX) / w
    endY = float(endY) / h

    data.append(image)
    labels.append(class_names[i])
    bboxes.append((startX, startY, endX, endY))

imagePaths.append(image_path)

My custom dataset class item is as follows,

 def __getitem__(self, index):
     image = self.tensors[0][index]
     label = self.tensors[1][index]
     bbox = self.tensors[2][index]
       
     image = image.permute(2, 0, 1)
     if self.transforms:
         image = self.transforms(image)
        
     return (image, label, bbox)

However, it throws the following error,

IndexError: index 43 is out of bounds for dimension 0 with size 4

How do I load bounding boxes and labels properly for a multiclass object detector?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source