Imagine having an Object Detection dataset with the annotations in the COCO format. How would you import annotations in such a case? Well, you can simply follow the steps mentioned on the Import annotations (Beta) page. Let's see how it works.
First, you need to create your Hasty project and upload images to it. These steps are straightforward and should not cause any trouble.
Second, you must create the label classes and attributes you will use in your project. Simply follow the guide from the documentation, and it will take you seconds to do. In our case, we have 404 images of Simpsons characters. The classes are the characters themselves - Homer, Marge, Maggie, Lisa, and Bart.
The COCO annotations for the dataset look as follows:
The only key in COCO annotations that is important for us is the "annotation" key. In Hasty JSON v1.1 format, all the annotation information (polygons, bounding boxes, classes, etc.) for each image is stored in the "labels" list inside each "images" instance. Filling the "labels" list with the corresponding annotations given in the COCO format is the key component for successful Import annotations (Beta) feature usage.
So, the third step is to export your project in the Hasty JSON v1.1 format through the Export data feature. This way, you will get a file in a necessary format that can be expanded with COCO annotations.
To export the project, just click on the three dots present in the
bottom right corner of the project and click on the Export data button.
By clicking the notification bell on the upper right side of the screen,
you can download the result of your export session. In the ZIP archive,
there will be a JSON file containing the information about your
This is what each instance in the "images" dictionary should look like:
Please notice that the "labels" list is empty because there are no annotations in the project so far. The goal is to fill the "labels"
list for each image using the COCO annotations. You need to do some
coding to copy the annotations from one file to another to succeed. But
do not worry. We have your back covered.
As a programming language, we suggest using Python. Let's start by loading the COCO annotations file.
The next step is to extract the annotation ids and image ids associated with each of the annotations from the imported file.
Then, we suggest creating a dictionary that stores the relevant information about the specific annotation for each image.
With that done, you can now store the annotations for each image in a format that Hasty will accept.
In the code block above, we create a new instance with the "polygon" and "class_name" field in the "labels" list. Notice that the polygon structure is different in Hasty and COCO. The COCO format has the following structure of polygon:
Whereas Hasty wants the polygon to look like this:
The following code does the job:
The class name is extracted from a dictionary called "cat" that contains the indices with the character's name.
At this point, the only task remaining is to add the annotations to the exported file.
We iterate through the empty labels of our original file, "simpsons_export.json", and replace them with annotations present in the allannot variable. Then we write this data in a new JSON file called "annotated_simpson.json".
The entire code looks like this:
Excellent, it is time to import the annotations!
Go to the project dashboard and click on the Import annotations (Beta) button.
Then create a new import and upload the expanded file in the Hasty JSON v1.1 format.
In our case, we named the import "Simpsons_labels". After the file is uploaded and checked, the import job will appear in the Import Jobs.
When the import is complete, the annotations will show up in the annotation environment.
Awesome, the labels are at their place! Also, please notice that all the annotated images are marked as "Done". This is the default setting for the import jobs but you can change it if you feel like it is needed.