> For the complete documentation index, see [llms.txt](https://docs.cloudfactory.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloudfactory.com/import-formats/supported-import-types.md).

# Supported import types

### Contents <a href="#contents" id="contents"></a>

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

#### **`bbox`** or **`polygon`** <a href="#strong-code-bbox-code-strong-or-strong-code-polygon-code-strong" id="strong-code-bbox-code-strong-or-strong-code-polygon-code-strong"></a>

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]]
      }
    ]
  }
]
```

### semantic <a href="#semantic" id="semantic"></a>

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\_class <a href="#label-class" id="label-class"></a>

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.

### RLE Encoding Example <a href="#rle-encoding-example" id="rle-encoding-example"></a>

```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
```

### Easiest way to import <a href="#easiest-way-to-import" id="easiest-way-to-import"></a>

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.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cloudfactory.com/import-formats/supported-import-types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
