Skip to content

assertion statement in apply_category_id_mapping of generic_video_dataset_parser #28

@Runinho

Description

@Runinho

Hi sabarim,

I think the assertion statement of

def apply_category_id_mapping(self, mapping):
assert set(mapping.keys()) == set(self.instance_categories.keys())
self.instance_categories = {
iid: mapping[current_cat_id] for iid, current_cat_id in self.instance_categories.items()
}

is not correct.
We use the mapping to rename the values of self.instance_categories, so we should check if the values of self.instance_categories are the same as the keys in the mapping.

This can be illustrated by the following example

from stemseg.data.generic_video_dataset_parser import GenericVideoSequence
seq = GenericVideoSequence(base_dir="some/dir",
                           seq_dict={"image_paths": ["1.png", "2.png"],
                                     "height": 128,
                                     "width": 256,
                                     "id": "some_id",
                                     "categories": {1: "Person", 2: "Car", 3: "Car"}})
seq.apply_category_id_mapping({"Person":11, "Car":22})

that fails with the following assertion

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "stemseg/data/generic_video_dataset_parser.py", line 107, in apply_category_id_mapping
    assert set(mapping.keys()) == set(self.instance_categories.keys())
AssertionError

While the following incorrect code passes the assertion check and fails with a KeyError:

from stemseg.data.generic_video_dataset_parser import GenericVideoSequence
seq = GenericVideoSequence(base_dir="some/dir",
                           seq_dict={"image_paths": ["1.png", "2.png"],
                                     "height": 128,
                                     "width": 256,
                                     "id": "some_id",
                                     "categories": {1: "Person", 2: "Car", 3: "Car"}})
seq.apply_category_id_mapping({1: 11, 2: 22, 3:33})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "stemseg/data/generic_video_dataset_parser.py", line 109, in apply_category_id_mapping
    iid: mapping[current_cat_id] for iid, current_cat_id in self.instance_categories.items()
  File "stemseg/data/generic_video_dataset_parser.py", line 109, in <dictcomp>
    iid: mapping[current_cat_id] for iid, current_cat_id in self.instance_categories.items()
KeyError: 'Person'

Thanks,
Runinho

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions