Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference between image_id and id in annotation key of coco annotation format #95

Open
AbuBakrCh opened this issue Dec 9, 2017 · 5 comments

Comments

@AbuBakrCh
Copy link

I am making annotation file for my own dataset. I am unable to understand what can be id in annotation key for my dataset?

@MonkeyWithAComputer
Copy link

I have the same question, have you figured it out?
annotation{
"id" : int, <---------------------what is this?
"image_id" : int,
"category_id" : int,
"segmentation" : RLE or [polygon],
"area" : float,
"bbox" : [x,y,width,height],
"iscrowd" : 0 or 1,
}

@saiabinesh
Copy link

Having the same doubt? Is that an annotation ID? Meaning does each annotation have it's own ID?

@cpoptic
Copy link

cpoptic commented Dec 17, 2018

I emailed info@cocodatset.org this exact question, but got no reply.

I found an article on creating your own COCO-style dataset and it appears the "id" is to uniquely identify each annotation. The "image_id", makes sense, but a unique id for each annotations seems overkill.
Basically you could just loop through every annotation in your dataset, assign an "id" counter to that annotation, and increment it for the next iteration.

http://www.immersivelimit.com/tutorials/create-coco-annotations-from-scratch

@Ostyk
Copy link

Ostyk commented Dec 29, 2020

Yup, it truly was is an overkill to assign a global unique ID to each annotation but that's the way it has to be according to the API.
It helped me after quite a bit of time trying to figure why I had so few annotations..

in the pythonAPI it's here in line 95 of coco.py

if 'annotations' in self.dataset:
            for ann in self.dataset['annotations']:
                imgToAnns[ann['image_id']].append(ann)
                anns[ann['id']] = ann

@cao13jf
Copy link

cao13jf commented Jun 17, 2021

Finally, I figure out the way to create a dataset according to the COCO format. All instance labels should be unique across all images. If you have a list of annotation matrix, e.g, [A_1, A_2, ..., A_n], the anns can be constructed by following these pseudo codes:

save_id = 1
for A in [A_1, A_2, ..., A_n]:
    for label in label_list_of_A:
        label_mask = A==save_id
        #  use pycocotools to get the annotations from label_mask
        #  ......
        save_id += 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants