jsbroks / coco-annotator

:pencil2: Web-based image segmentation tool for object detection, localization, and keypoints
MIT License
2.12k stars 462 forks source link

Import own annotation error #311

Open JeongChanwoo opened 4 years ago

JeongChanwoo commented 4 years ago

My annotations based on coco-api, coco dataset won't import. error. I ran coco-annotator based on docker. The error details are as follows.

annotator_workers | Traceback (most recent call last): annotator_workers | File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 382, in trace_task annotator_workers | R = retval = fun(*args, kwargs) annotator_workers | File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 641, in __protected_call__ annotator_workers | return self.run(*args, *kwargs) annotator_workers | File "/workspace/workers/tasks/data.py", line 266, in import_annotations annotator_workers | annotation_model.save() annotator_workers | File "/workspace/database/annotations.py", line 77, in save annotator_workers | return super(AnnotationModel, self).save(args, kwargs) annotator_workers | File "/usr/local/lib/python3.6/site-packages/mongoengine/document.py", line 369, in save annotator_workers | self.validate(clean=clean) annotator_workers | File "/usr/local/lib/python3.6/site-packages/mongoengine/base/document.py", line 392, in validate annotator_workers | raise ValidationError(message, errors=errors) annotator_workers | mongoengine.errors.ValidationError: ValidationError (AnnotationModel:863) (Only lists and tuples may be used in a list field: ['segmentation'])

jsbroks commented 4 years ago

Could you share an annotation in the coco format?

JeongChanwoo commented 4 years ago

Thank you for the reply @jsbroks .

The file is attached via a shareable link_googledrive. (https://drive.google.com/open?id=1CsImi6YGsAlJRWKbbzd5NqHsovJzyi1A) It is based on the files provided by the Coco site. An additional variation is the RGB color per label.

The code is the function I wrote to create the annotation json file.

def json_generator(dir_path,  catlist, images, train=True):
    if train:
        save_path = os.path.join(dir_path,'train')
        if not os.path.exists(save_path):
            os.makedirs(save_path)
        save_name = save_path + '/' + 'annotation_train_2.json'
    else:
        save_path = os.path.join(dir_path,'test')
        save_name = save_path + '/' + 'annotation_test_2.json'
        if not os.path.exists(save_path):
            os.makedirs(save_path)
    with open(save_name,'w') as json_file:
        ann_data = {}
        categories = []
        for cat_idx, cat in enumerate(catlist):
            cat['color'] = color_list[cat_idx]
            categories.append(cat)
            print(cat)
        ann_data['categories'] =categories 
        ann_data['images'] = images
        annotations = []
        for im in tqdm(images):
            for cat_idx,  cat in enumerate(catIds):
                annIds = coco.getAnnIds(imgIds=im['id'], catIds=cat, iscrowd=None)
                anns = coco.loadAnns(annIds)
                for i in range(len(anns)):
                    ann_mini = anns[i]
                    ann_mini['color'] = color_list[cat_idx]
                    annotations.append(ann_mini)
        ann_data['annotations'] = annotations
        json.dump(ann_data, json_file)
        json_file.close()
EtienneDavid commented 4 years ago

to help you to format your data you can use https://www.github.com/jsbroks/imantics/ (install from source, not from pip)

If the error come the segmentation part, please check in which format your mask are. I think pycocotools convert to the RLE format https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/mask.py

JeongChanwoo commented 4 years ago

This dataset is coco-annotation dataset provided by coco site. The json file only extracts dog and people category data, and then adds color labels. So the input is in RLE format. However, it doesn't work.

JeongChanwoo commented 4 years ago

I checked, I typed in polygon form. So, I'll convert it to an RLE annotation and try again.

In addition, is the export annotations restricted to polygon styles? There is no iscrowd setting, so I think it is iscrowd 0 in the restricted result.