COCO Annotations on BasicAI

🥥 Introducing the COCO data format and its import/export in BasicAI image annotation tool.

The COCO format is a widely used standard for object detection, segmentation, and captioning, offering detailed annotations for various computer vision tasks.

For more information, please visit the COCO site.

On the BasicAI labeling platform, you can import and export annotation results in COCO format for 2D object detection, which will be detailed in this article.

You can download COCO datasets from the official website or find samples here📂.


Import COCO to BasicAI

When uploading pre-labeled COCO datasets to BasicAI, the annotation information for all images should be stored in a single JSON file with the following structure:

❗️

Please don't use comments in the JSON file.

{
  "info": { // General information about the dataset. Not required.
    "year" : int, 
    "version" : str, 
    "description" : str, 
    "contributor" : str, 
    "url" : str, 
    "date_created" : datetime,
  },
  "licenses": [{ // A list of license information for the images in the dataset. Not required.
    "id" : int, 
    "name" : str, 
    "url" : str,
  }],
  "images": [{ // A list of image data in the dataset. Required.
    "id" : int, 
    "width" : int, 
    "height" : int, 			
    "file_name" : str, 
    "license" : int, 
    "flickr_url" : str, 
    "coco_url" : str, 
    "date_captured" : datetime,
  }],
  "annotations": [{ // A list of annotations included in all dataset images. Required.
    "id" : int, 
    "image_id" : int, 
    "category_id" : int, 
    "segmentation" : RLE or [polygon], 
    "area" : float, 
    "bbox" : [x,y,width,height], 
    "iscrowd" : 0 or 1,
  }],
  "categories": [{ // A list of label or class categories. Required.
    "id" : int, 
    "name" : str, 
    "supercategory" : str,
  }]
}

The COCO JSON file contains five sections of information, including three required sections (images, annotations, categories), and other optional sections (info, licenses). We will further explain the required ones. Click to expand details:

🏙️ images

The COCO image list contains information about the images in the dataset, including the following fields:

  • id: (Required) A unique identifier for the image. It maps to the image_id field in the annotation list.
  • width: (Required) The width of the image.
  • height: (Required) The height of the image.
  • file_name: (Required) The image file name.
  • license: (Not Required) Maps to the license list.
  • coco_url: (Not Required) The location of the image. If you upload the image as a local file, you don't need to fill in this field.
  • flickr_url: (Not Required) The location of the image on Flickr, a photo storage platform.
  • date_captured: (Not Required) The date and time the image was taken.
✏️ annotations

The annotations list stores the bounding box information for all objects in all images. Each instance corresponds to an annotation.

  • id: (Required) The identifier of the annotation.
  • image_id: (Required) Indicate which image the annotation appears in. It maps to the id field in the images list.
  • category_id: (Required) The identifier for labeling the object within the bounding box. It maps to the id field of the categories list. If there's no label information, the value is -1.

🚧

Please note the difference between id (of annotation), image_id, and category_id. The same image may have multiple annotations, and the corresponding category_id may be different.

  • area: (Required) The area of the annotation, equivalent to the area of the bounding box in BasicAI.
  • bbox: (Required) Contains the coordinates and size, in pixels, of a bounding box around an object. [x,y] represents the coordinates of the upper left corner of the bbox.
  • iscrowd: (Not Required) Indicates if the image contains a crowd of objects; 0 for a single object and 1 for a crowd.
  • segmentation: (Not Required) The segmentation information for objects in an image, formatted based on the instance type: for a single object (iscrowd=0), it uses formatted polygons represented by vertices, while for a group of objects (iscrowd=1), it uses RLE format for mask encoding.

📘

In the BasicAI annotation tool, the default value of iscrowd is 0, and the segmentation value is empty.

🏷 categories

The categories list holds the dataset's label or class information, corresponding to the Class in BasicAI's ontology.

📘

If your data is annotated only with bounding boxes and lacks label information, the list will be empty.

  • supercategory: (Not required) The parent category for a label or class.
  • id: (Required) The identifier of the label or class. It maps to the category_id field in the annotations list.
  • name: (Required) The name of the label or class.

Here is an example COCO annotation file:

{
  "info": {}, 
  "licenses": [], 
  "images": [
    {"file_name": "0002.jpeg", "height": 410, "width": 639, "id": 1}, 
    {"file_name": "0003.jpeg", "height": 411, "width": 640, "id": 2}, 
    {"file_name": "0004.png", "height": 480, "width": 640, "id": 3}
  ],
  "annotations": [
    {"area": 6016, "image_id": 1, "bbox": [0, 309, 94, 64], "iscrowd": 0, "segmentation": [], "category_id": 1, "id": 1}, 
    {"area": 6468, "image_id": 1, "bbox": [354, 343, 98, 66], "iscrowd": 0, "segmentation": [], "category_id": 1, "id": 2}, 
    {"area": 7426, "image_id": 2, "bbox": [42, 246, 94, 79], "iscrowd": 0, "segmentation": [], "category_id": 2, "id": 3}, 
    {"area": 336, "image_id": 3, "bbox": [26, 193, 16, 21], "iscrowd": 0, "segmentation": [], "category_id": -1, "id": 4}
  ],
  "categories": [
    {"supercategory": "Car", "id": 1, "name": "Car"}, 
    {"supercategory": "Truck", "id": 2, "name": "Truck"}
  ]
}

After organizing the COCO data into a zip archive, you can upload it to the Image dataset on BasicAI. Remember to click the Config switch button, select COCO as the format, and import pre-annotations.

For more details about creating datasets and uploading data, please refer to Data and Folder Structure.

upload COCO data and annotation to BasicAI

Access the Image Tool to load pre-annotations from the top right corner and label the data.

annotate COCO image data in BasicAI

Export COCO from BasicAI

You can export annotation results in the COCO format from BasicAI.

For more details about exporting, please refer to Export.

export coco annotations from BasicAI

For export of results:

  1. Only the bounding box results for object detection can be exported in COCO format.
  2. The object Attribute cannot be exported.
  3. For details about the exported COCO annotation file, please refer to the Import section.

👍

If you encounter any issues with importing or exporting your COCO-like data, feel free to seek assistance on our Slack channel or through email [email protected] 📧.