Annotation import

Contents

Hasty support an import of existing annotations of the following types:

  • bbox - Bounding boxes (as a JSON file)

  • polygon - Polygons (as a JSON file)

  • mask - Mask (as a png image and JSON)

  • semantic - Semantic segmentation (as a PNG image)

  • label_class - Label classes (as a JSON file)

  • hasty_export - JSON File with a structure of the Hasty Export

bbox or polygon

The JSON should be of the following format:

{
"definitions": {},
"type": "array",
"title": "Array of Images",
"items": {
"type": "object",
"title": "Image",
"required": [
"image_name",
"labels"
],
"properties": {
"image_name": {
"type": "string",
"title": "Image file name",
"default": "",
"examples": [
"2010_000001.jpg"
]
},
"labels": {
"type": "array",
"title": "Image labels",
"items": {
"type": "object",
"title": "Image label",
"required": [
"class_name",
"bbox"
],
"properties": {
"class_name": {
"type": "string",
"title": "Name of the label class",
"default": "",
"examples": [
"ground"
]
},
"bbox": {
"type": "array",
"title": "Bounding box coordinates [X_top_left, Y_top_left, X_bottom_right, Y_bottom_right]",
"items": {
"type": "integer",
"examples": [
3,
12,
500,
295
]
}
},
"polygon": {
"type": "array",
"title": "Polygon coordinates [[x0, y0], [x1, y1], ...]",
"items": {
"type": "array",
"items": {
"type": "integer",
"examples": [
202,
13
]
}
}
}
}
}
}
}
}
}

As an example, here are two annotations, one bounding box (cat) and one polygon (dining table):

[
{
"image_name": "2010_000001.jpg",
"labels": [
{
"class_name": "cat",
"bbox": [128, 13, 340, 308]
}
]
},
{
"image_name": "2010_000001.jpg",
"labels": [
{
"class_name": "diningtable",
"polygon": [[122, 222], [73, 236], [72, 250], [2, 256], [2, 332], [498, 332],
[498, 295], [429, 260], [339, 231], [282, 223], [297, 246], [306, 285], [280, 302],
[255, 271], [224, 260], [222, 304], [199, 310], [171, 290], [171, 265],
[131, 244], [128, 222]]
}
]
}
]

mask

Each mask should be added as a separate *.png file. It should contain a single channel with 0 as a background and 1 or 255 for mask. It's important that the Image size matches the size of the original image.

Also the mapping of the mask filename to image name should be included.

The format of the mask metadata file is the following:

{
"type": "array",
"title": "Array of image - masks pairs",
"items": {
"type": "object",
"required": [
"image_name",
"label_class_name",
"mask_filename"
],
"properties": {
"image_name": {
"type": "string",
"title": "Image filename",
"default": "",
"examples": [
"2010_000001.jpg"
]
},
"label_class_name": {
"type": "string",
"title": "Label class name",
"examples": [
"cat"
]
},
"mask_filename": {
"type": "string",
"title": "Mask filename",
"examples": [
"2010_000001_cat_1.0.png"
]
}
}
}
}

Example:

[
{
"image_name": "2010_000001.jpg",
"label_class_name": "cat",
"mask_filename": "2010_000001_cat_1.0.png"
},
{
"image_name": "2010_000001.jpg",
"label_class_name": "diningtable",
"mask_filename": "2010_000001_diningtable_1.0.png"
}
]

semantic

Each file with a semantic segmentation should be an image in *.png format. The filename should be the same (without extension) as the corresponding image's name. The image file should contain only one channel. 0 value of pixel considered as a background.

label_class

Label classes can be imported through the use of a JSON-file with in the following schema:

{
"$id": "http://example.com/root.json",
"type": "array",
"title": "List of Label Classes",
"items": {
"type": "object",
"title": "Label class",
"required": [
"class_name",
"class_type"
],
"properties": {
"class_name": {
"type": "string",
"title": "Class name",
"examples": [
"floor"
]
},
"color": {
"type": "string",
"title": "Class color (can be assigned automatically)",
"examples": [
"#F453A3"
]
},
"class_type": {
"type": "string",
"title": "object or background",
"default": "object",
"examples": [
"background"
]
}
}
}
}

As an example:

[
{
"class_name": "floor",
"class_type": "background"
},
{
"class_name": "flower",
"class_type": "object"
},
{
"class_name": "food",
"class_type": "object"
},
{
"class_name": "grass",
"class_type": "background"
}
]

As you can see, there are two types of classes: object (1) and background (2). These correspond to the foreground (1) and semantic (2) classes you see in the tool.

We are aware that class_type names can be confusing and we are looking to change this in a near future.