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

  • bbox - Bounding boxes (as a JSON file)
  • polygon - Polygons (as a JSON file)
  • 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 JSON V1.1

The JSON should be of the following format:

json
      {
  "project_name": "Project Name",
  "create_date": "2019-10-22 19:04:16Z",
  "export_format_version": "1.1",
  "export_date": "2019-11-19 16:21:18Z",
  "attributes": [
    {
      "name": "ewerwer",
      "type": "TEXT",
      "values": [
        "black",
        "white"
      ]
    }
  ],
  "label_classes": [
    {
      "class_name": "cat",
      "color": "#1f78b44d",
      "class_type": "object",
      "attributes": [
        "black",
        "white"
      ]
    },
    {
      "class_name": "dog",
      "color": "#e31a1c4d",
      "class_type": "object"
    }
  ],
  "images": [
    {
      "image_name": "IMG_000002.jpg",
      "dataset_name": "train dataset",
      "width": 500,
      "height": 430,
      "image_status": "TO REVIEW",
      "labels": [
        {
          "class_name": "cat",
          "bbox": [
            102,
            45,
            420,
            404
          ],
          "polygon": null,
          "mask": null,
          "z_index": 1,
          "attributes": {
            "attribute_name": "xyz"
          }
        }
      ],
      "tags": [
        "xyz",
        "pqr"
      ]
    }
  ]
}
    

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

json
      [
  {
    "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]]
      }
    ]
  }
]
    

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 can contain one or three channels.

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

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

As an example:

json
      [
  {
    "color": "#8000ff4d",
    "png_index": 1,
    "name": "wall",
    "type": "background"
  },
  {
    "color": "#396bf94d",
    "png_index": 17,
    "name": "plate",
    "type": "object"
  }
]
    

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.

python
      def rle_encoding(x: np.array):
    """
    Encode binary mask to RLE
    Args:
        x (np.array): numpy array of shape (height, width), 1 - mask, 0 - background
    Returns run length as list
    """
    dots = np.where(x.flatten() == 1)[0]  # Order right-then-down
    run_lengths = []
    prev = -2
    for b in dots:
        if b > prev + 1:
            run_lengths.extend((b + 1, 0))
        run_lengths[-1] += 1
        prev = b
    return run_lengths
    

If you are looking to import masks or do other, more complex imports with attributes and image tags as well as annotations, you need to format your data into our own supported Hasty JSON v1.1.

Boost model performance quickly with AI-powered labeling and 100% QA.

Learn more
Last modified