airctic / icevision

An Agnostic Computer Vision Framework - Pluggable to any Training Library: Fastai, Pytorch-Lightning with more to come
https://airctic.github.io/icevision/
Apache License 2.0
848 stars 150 forks source link

Tutorial on COCO and VOC parsers #187

Closed lgvaz closed 4 years ago

lgvaz commented 4 years ago

📓 New Tutorial

COCO and VOC are the two most common annotation formats, we need a tutorial (or two, one for each) that shows how to use them.

mentioned in #79


Don't remove Main issue for examples: #39

shimsan commented 4 years ago

@lgvaz , you think it is a good idea to have mantisshrimp automatically create the classes dictionary mapping IDs to labelnames?

The annotations.json have both a category_id and a category_name.

I was trying to create a tutorial for COCO Object Detection, but then realized, I might need to parse the JSON myself to get this info out, which seems redundant.

I would do something like this (code from fastai's get_annotations):

annot_dict = json.load(open(fname))
classes = {o['id']:o['name'] for o in annot_dict['categories']}
lgvaz commented 4 years ago

This is a topic that we've been internally discussing in the past weeks.

It's very hard to write an automated extractor of classes that safely works for all use cases (all Parsers). But we might be able to design something specific for COCO.

The solution we came for now, is to let the user figure out how to create classes, and let him handle the conventions (because we cannot make any assumptions)

But maybe we can provide some helper functions so the standard use case is facilidated... I'm open to ideas =)

shimsan commented 4 years ago

The standard COCO JSON will already contain the category_ids and category_names.

    "categories": [
        {
            "id": 0,
            "name": "Background"
        },
        {
            "id": 1,
            "name": "Label1"
        },
        {
            "id": 2,
            "name": "Label2"
        },
        {
            "id": 3,
            "name": "Label3"
        },
}

So, it is matter of reading the JSON which is already being done with the COCO parser.

But, you have already implemented a Helper function which now makes this simpler.

I agree that the user needs to understand the model they want to use and the requirements thereof.

lgvaz commented 4 years ago

I just merged this helper function, you can now do:

class_map = datasets.coco.class_map("path_to_annotations_file", background=0)

This assumes that background is not already present in your categories, if it's (or you don't need a background id), you can do background=None

lgvaz commented 4 years ago

Done! See tutorials on the docs =)