Bounding box (self.items problem)

Hi all,

I am trying to use bounding boxes for a custom application.

I have a CSV with 5 columns:

  1. Image name
  2. Top left x
  3. Top left y
  4. Bottom right x
  5. Bottom right y

Here is my dataframe with 5 sample rows:

I tried to customise the label_cls by using a custom class, since ObjectItem is needed for bounding box predictions.

class ObjectList(ObjectCategoryList):
    "`ItemList` for labelled bounding boxes."
    _processor = ObjectCategoryProcessor
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.items = [[[int(i) for i in item], [5]] for item in self.items] #using [5] to simplify 
    def get(self, i):
        print('Element: ', i)
        return MyBox.create(*_get_size(self.x,i), *self.items[i], classes=self.classes, pad_idx=self.pad_idx)

First print in init, prints self.items as following:

[[[218, 190, 233, 236], [5]], [[275, 225, 293, 272], [5]], [[254, 242, 280, 315], [5]], [[297, 170, 317, 222], [5]], [[317, 212, 339, 258], [5]]]

While second print in get(self, i) prints self.items for all elements like this:

Element: 0
[list([218, 190, 233, 236]) list([1])]

I am unable to understand why self.items changes data from [[[ ]]] to [list() list()]. It’s causing me problem downstream as data expected by create API is not as expected.

Also, I am not sure why list([1]) comes in second print while I passed [5], which is correctly reflected in self.items first print. Seems I am missing some manipulation somewhere…

Any pointers will be appreciated.


That’s expected - an item is a list containing a list of lists of coordinates and a list of corresponding classes.

Also, I am not sure why list([1]) comes in second print while I passed [5],

All classes are mapped to integers, even if they are integers.

Pascal notebook in course-v3/dl2 might be helpful for you.

I think the convention for bbox coordinates is top, left, bottom, right which is basically top y, left x, bottom y, right x.

Thanks Valeriy.

I understand the format expected and as you can see from first print, the format is per expectation. Question is why is the same list is projected differently in another function which causes things to mess up down the chain, when I am not modifying anything.

I have already gone through both COCO and Pascal; since their annotations are different to mine I could not use them. That’s why I have used my own class to get past that…

And yes, co-ordinates are correct as I used ImageBBox directly on a couple of images with the co-ordinates in the dataframe and image worked well. Problem is the inability to create an accurate labelled list.

That will run after your first print. and modifies items. You can later get back that the class with index 1 was 5, so not sure why would you want to prevent it.

1 Like

Thanks for the tip! I am going to debug that and get back here with findings… :grinning: