Uploading Annotations

In this tutorial, we explore some of different options available to upload annotations in Remo. We will: - introduce the concept of Annotation set - add annotations using a file format supported by Remo - add annotations directly from code - add annotations using custom files formats

We start off by creating a dataset and populating it with some images

%load_ext autoreload
%autoreload 2
import remo
import os
import pandas as pd

urls = ['https://remo-scripts.s3-eu-west-1.amazonaws.com/open_images_sample_dataset.zip']
my_dataset = remo.create_dataset(name = 'D1', urls = urls)
Launching Remo server ...
Wait a bit...  5

    (>':') Remo server is running: {'app': 'remo', 'version': '0.3.10-53-g3012aa79'}

Annotation set

Annotation sets represent a collection of annotations for all the images within a Dataset. An annotation set is characterized by a task (such as 'Object Detection') and a list of classes.

The advantage of grouping annotations in an Annotation Set is that it allows for high-level group operations on all the annotations, such: - grouping classes together - deleting objects of specific classes - comparing of different annotations (such as ground truth vs prediction, or annotations coming from different annotators)

Let's first create an empty annotation set with a predetermined list of classes

my_classes = ['Airplane', 'Clothing', 'Dog', 'Fashion accessory', 'Food', 'Footwear', 'Fruit', 'Human arm', 
         'Human body', 'Human hand', 'Human leg', 'Mammal', 'Man', 'Person', 'Salad', 'Sports equipment', 'Trousers', 'Woman']

annotation_set = my_dataset.create_annotation_set(annotation_task = 'Object detection',
                                          name = 'Objects',
                                          classes = my_classes)

We can easily retrieve different annotation sets of a dataset

[Annotation set 17 - 'Objects', task: Object detection, #classes: 18]

Add annotations from supported CSV file format

Let's add some annotations from a CSV file

In this example, annotations are stored in a CSV file in a format already supported by Remo. Class labels were encoded using GoogleKnowledgeGraph.

annotation_files=[os.getcwd() + '/assets/open_sample.csv']

df = pd.read_csv(annotation_files[0])
Index(['ImageID', 'Source', 'LabelName', 'Confidence', 'XMin', 'XMax', 'YMin',
       'YMax', 'IsOccluded', 'IsTruncated', 'IsGroupOf', 'IsDepiction',

When adding the file to the annotation set, remo automatically: - detects the class encoding and translates it into the corresponding labels - only adds annotations for classes that are part of the existing annotation set

my_dataset.add_data(local_files=annotation_files, annotation_task = 'Object detection')
{'files_link_result': {'files uploaded': 0, 'annotations': 9, 'errors': []}}
[{'AnnotationSet ID': 17,
  'AnnotationSet name': 'Objects',
  'n_images': 9,
  'n_classes': 18,
  'n_objects': 84,
  'top_3_classes': [{'name': 'Fruit', 'count': 27},
   {'name': 'Sports equipment', 'count': 12},
   {'name': 'Mammal', 'count': 7}],
  'creation_date': None,
  'last_modified_date': '2020-03-08T16:35:05.643905Z'}]
Open http://localhost:8123/datasets/26


Add annotations from code

Let's see how we can add annotations to a specific image from code

This can be useful for instance to add model predictions as annotations or to tag specific images.

First, let's retrieve one image

images = my_dataset.images()
my_image = images[1]
print('Resoultion: ', my_image.width, 'x', my_image.height)
Image: 936 - 000a1249af2bc5f0.jpg
Resoultion:  1024 x 678

Now we can add annotations using the Annotation class

We can add an annotation object to either the annotation set or directly to an image

annotation = remo.Annotation()
annotation.add_item(classes=['Human hand'], bbox=[227, 284, 678, 674])
annotation.add_item(classes=['Human hand'], bbox=[311, 193, 607, 526])

annotation_set.add_annotation(my_image.id, annotation)
annotation = remo.Annotation()
annotation.add_item(classes=['Fashion accessory'], bbox=[496, 322, 544,370])

Open http://localhost:8123/image/936?dataset_id=26


TODO: Add annotations from custom file