> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/zh/apis/annotation-json-reference.md).

# 标注 JSON 参考

Unitlab 标注 JSON 格式参考：每个条目的 UUEF 文档、地理空间模型使用的 GeoJSON，以及图像模型的预测格式，含边界框、多边形、掩码和视频轨迹。

Unitlab 使用三种 JSON 结构表示标注：

| 结构                                               | 使用场景                                                                                 |
| ------------------------------------------------ | ------------------------------------------------------------------------------------ |
| **UUEF**（每个条目一个 JSON 文档）                         | UUEF 格式的发布导出、标注导入、Agent 阶段的读取与保存                                                     |
| **GeoJSON（地理空间模型）**，即 RFC 7946 FeatureCollection | 地理空间模型返回给 Model 阶段的结果。Agent 保存时以 `format="geojson"` 接受它。                             |
| **预测格式（图像模型）**                                   | 在 **My AI Models** 下接入的图像模型返回给 Unitlab 的预测结果。Agent 保存时以 `format="model"` 接受同样的 JSON。 |

其他导出格式见 [导出格式与源文件](https://docs.unitlab.ai/documentation/zh/releases/export-formats-and-source-inclusion)。要将已有标注导入项目，参见 [标注导入](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/annotation-imports.md)。要接入自己的模型，参见 [接入自有模型](https://docs.unitlab.ai/documentation/zh/auto-labeling/bring-your-own-models)。

{% hint style="info" %}
**坐标**均为原始媒体的像素坐标：x 向右，y 向下，(0, 0) 位于左上角。这适用于图像、视频帧、医学影像切片、PDF 页面，以及全分辨率下的大尺寸栅格图像和切片。地理空间模型也可以改用地图坐标返回结果（见 [GeoJSON（地理空间模型）](#geojson-for-geospatial-models)）。
{% endhint %}

## UUEF 文档 <a href="#uuef-document" id="uuef-document"></a>

UUEF 发布中的每个条目是一个 JSON 文档。每个 UUEF 发布压缩包的根目录都包含 JSON Schema 文件 `uuef.schema.json`。

```json
{
  "version": "1.0",
  "media": {
    "filename": "street_001.jpg",
    "media_type": "Image",
    "origin": {"media_id": "…", "release_id": "…", "release_version": "v1"},
    "source_url": "https://…",
    "width": 1920,
    "height": 1080
  },
  "labels": [
    {
      "id": "b7c1…",
      "value": 1,
      "geometry": {"type": "bbox", "points": [[100, 50], [300, 50], [300, 200], [100, 200]]},
      "properties": [{"id": 3, "name": "Occluded", "type": "boolean", "value": false}],
      "attributes": {}
    }
  ],
  "classes": [
    {"name": "Car", "value": 1, "markup_type": "bbox", "color": "#e5484d", "attributes": [], "properties": []}
  ],
  "item_property_definitions": [],
  "item_properties": [],
  "data_tags": [],
  "relations": []
}
```

### 顶层字段 <a href="#top-level-fields" id="top-level-fields"></a>

| 字段                                             | 含义                                                                                                                                                                                                                        |
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `version`                                      | 始终为 `"1.0"`。                                                                                                                                                                                                              |
| `media`                                        | 条目信息：`filename`、`media_type`、`origin`（条目及其来源发布）、`source_url`（指向原始文件的链接），并根据数据类型包含 `width`/`height`、`total_frames`/`fps`/`duration`、`page_count`，地理空间栅格则包含 `geospatial`（`crs`、`transform`、`bounds_native`、`bounds_wgs84`）。 |
| `classes`                                      | 项目的类别：`name`、`value`（标注引用的类别编号）、`markup_type`、`color`，以及该类别的 `attributes` 和 `properties` 定义。                                                                                                                              |
| `labels`                                       | 条目上的对象（见下文）。                                                                                                                                                                                                              |
| `item_property_definitions`, `item_properties` | 条目级属性：属性定义及该条目上设置的值。                                                                                                                                                                                                      |
| `data_tags`                                    | 条目上的标签。                                                                                                                                                                                                                   |
| `relations`                                    | 标注之间的关系（见下文）。                                                                                                                                                                                                             |
| `group`                                        | 仅当条目是 Data Group 中的一个面板时出现：标明所属分组和面板。                                                                                                                                                                                     |

### 标注对象 <a href="#labels" id="labels"></a>

每个标注都包含：

| 字段            | 含义                                                       |
| ------------- | -------------------------------------------------------- |
| `id`          | 对象 ID，在各版本和各发布之间保持不变。                                    |
| `value`       | 类别编号：`classes` 中某一项的 `value`。                            |
| `properties`  | `{id, name, type, value}` 列表。选择类属性带有所选选项的 `id` 和 `name`。 |
| `attributes`  | 该类别的属性值。                                                 |
| `page_number` | 仅 PDF：页码，从 1 开始。                                         |

并且恰好包含一种形状：

| 形状  | JSON                                                                                        |
| --- | ------------------------------------------------------------------------------------------- |
| 边界框 | `"geometry": {"type": "bbox", "points": [[x, y], [x, y], [x, y], [x, y]]}`：四个角点，从左上角开始顺时针排列 |
| 多边形 | `"polygon": {"paths": [[[x, y], …], [[x, y], …]]}`：先是外轮廓，然后每个孔洞一条路径                         |
| 掩码  | `"mask": {"rle": […], "left": 10, "top": 20, "width": 64, "height": 48}`（见下文）               |
| 点   | `"point": [x, y]`                                                                           |
| 折线  | `"polyline": {"point": [[x, y], …]}`                                                        |
| 骨架  | `"skeleton": {"point": [[x, y], …]}`                                                        |
| 长方体 | `"cuboid": {"point": [[x, y], …]}`：八个角点，按编辑器中的顺序排列                                          |

**掩码编码。** `left`、`top`、`width` 和 `height` 给出掩码覆盖的矩形。`rle` 从左上角像素开始逐行覆盖该矩形，以空像素和填充像素交替计数。第一个计数是空像素数，如果第一个像素是填充的则为 `0`。例如：`[3, 2, 5]` 表示 3 个空像素、2 个填充像素，再是 5 个空像素。

文本、音频和时间序列标注使用 `type` 而不是形状：

| 数据类型 | 标注                                                                                                             |
| ---- | -------------------------------------------------------------------------------------------------------------- |
| 文本   | `"type": "entity"`，带字符偏移量表示的 `span: {start, end, text}`；整段文本分类使用 `"type": "classification"`                    |
| 音频   | `"type": "event"`，带以秒为单位的 `interval: {start, end}`；整个文件分类使用 `"type": "classification"`                         |
| 时间序列 | `"type": "interval"` 带 `interval: {start, end}`，或 `"type": "instant"` 带 `instant: {x}`，单位与 X 列一致（日期为 UTC 纪元毫秒） |

### 视频与医学影像：轨迹 <a href="#video-and-medical-tracks" id="video-and-medical-tracks"></a>

在视频或医学影像体数据中，每个标注都是一条轨迹：即跨帧（医学影像为切片）跟踪的同一个对象。

```json
{
  "id": "car-1",
  "value": 1,
  "ranges": [[0, 3]],
  "track": {
    "0": {"keyframe": true,  "geometry": {"type": "bbox", "points": [[10, 10], [50, 10], [50, 40], [10, 40]]}},
    "1": {"keyframe": false, "geometry": {"type": "bbox", "points": [[12, 10], [52, 10], [52, 40], [12, 40]]}},
    "2": {"keyframe": true,  "geometry": {"type": "bbox", "points": [[14, 10], [54, 10], [54, 40], [14, 40]]}}
  },
  "properties": [],
  "attributes": {}
}
```

| 字段              | 含义                                                            |
| --------------- | ------------------------------------------------------------- |
| `ranges`        | 对象存在的范围，以 `[start, end]` 帧号表示：包含 `start`，不包含 `end`。帧号从 0 开始。  |
| `track`         | 每个帧号一项，每项使用与上文相同的形状。                                          |
| `keyframe`      | 由人或模型放置的帧为 `true`；在关键帧之间插值填充的帧为 `false`。发布会列出 `ranges` 内的每一帧。 |
| `hidden_ranges` | 可选：对象被关闭显示的帧范围。                                               |
| `plane`         | 仅医学影像：轨迹所在的视图（`sagittal` 或 `coronal`）。缺失时为轴位视图。帧号即该视图的切片号。    |

### 关系 <a href="#relations" id="relations"></a>

```json
{"id": "r1", "type_id": 2, "type": "drives", "source_id": "person-1", "target_id": "car-1"}
```

`source_id` 和 `target_id` 是标注的 `id`。源或目标不在 `labels` 中的关系会被省略。

## GeoJSON（地理空间模型） <a href="#geojson-for-geospatial-models" id="geojson-for-geospatial-models"></a>

自定义地理空间模型用 GeoJSON `FeatureCollection`（RFC 7946）响应 Model 阶段，也可以封装为 `{"status": "complete", "result": {…}}`。

```json
{
  "type": "FeatureCollection",
  "classes": ["building", "road"],
  "features": [
    {
      "type": "Feature",
      "geometry": {"type": "Polygon", "coordinates": [[[69.2401, 41.2995], [69.2410, 41.2995], [69.2410, 41.3001], [69.2401, 41.3001], [69.2401, 41.2995]]]},
      "properties": {"class_name": "building", "markup_type": "polygon", "confidence": 0.93}
    }
  ]
}
```

| 字段                       | 含义                                                        |
| ------------------------ | --------------------------------------------------------- |
| `classes`                | 模型的类别：名称，或 `{name, markup_type}` 对象。类别编号是其在列表中的位置，从 0 开始。 |
| `properties.class_name`  | 按名称指定类别。也可以用 `properties.class` 给出类别编号。                   |
| `properties.markup_type` | 可选：`bbox`、`polygon`、`mask`、`line` 或 `point`。省略时根据几何类型推断。  |
| `properties.confidence`  | 可选，0 到 1。                                                 |

几何类型及其转换后的形状：

| 几何类型           | 转换为                         |
| -------------- | --------------------------- |
| `Point`        | 点                           |
| `LineString`   | 折线                          |
| `Polygon`      | 多边形（默认）、边界框或掩码。第一个环之后的环为孔洞。 |
| `MultiPolygon` | 每个部分一个多边形或掩码                |

坐标可以是经纬度（WGS84）、栅格自身的地图单位或栅格像素，Unitlab 会根据整个响应自动判断。超出栅格范围的形状会被裁剪到边缘。

Agent 阶段保存（`format="geojson"`，用于地理空间和病理条目）接受不带 `classes` 列表的同样要素：`properties.class_name` 为项目类别名称，或 `properties.class` 为项目类别值，要素的 `id` 成为对象 ID。病理切片使用像素坐标。

## 预测格式（图像模型） <a href="#prediction-format-image-models" id="prediction-format-image-models"></a>

在 **My AI Models** 下接入的图像模型返回给 Unitlab 的预测结果。Agent 保存时以 `format="model"` 接受同样的 JSON。请求和响应的权威说明见 [接入自有模型](https://docs.unitlab.ai/documentation/zh/auto-labeling/bring-your-own-models#representative-image-request)，其中的 [验证](https://docs.unitlab.ai/documentation/zh/auto-labeling/bring-your-own-models#validation) 步骤会检查模型的响应；下面的键只是简要概括。

Unitlab 向模型发送一个 JSON POST 请求，包含 `src`（图像的临时链接）以及模型已保存的参数。模型为其生成的每种形状返回一个对象列表，并附带 `classes`：

```json
{
  "classes": ["car", "person"],
  "bboxes": [[{"point": [[100, 50], [300, 50], [300, 200], [100, 200]], "class": 0}]],
  "polygons": [{"point": [[10, 10], [80, 12], [60, 90]], "class": 1}]
}
```

| 键           | 每个对象                                                                                                                                                               |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `classes`   | 模型的类别名称。每个对象中的 `class` 是在此列表中的位置，从 0 开始。                                                                                                                           |
| `bboxes`    | `{point, class}` 的列表的列表。`point` 为四个 `[x, y]` 角点。                                                                                                                   |
| `polygons`  | `{point, class}`，至少三个 `[x, y]` 点。                                                                                                                                  |
| `brush`     | 像素掩码 `{rle, left, top, right, bottom, value}`（`right` 和 `bottom` 是最后一个填充的列和行；`rle` 同 [掩码编码](#labels)），或轮廓 `{point, holes, value, vector_brush: true}`。`value` 为类别。 |
| `points`    | `{point: [x, y], class}`                                                                                                                                           |
| `lines`     | `{point: [[x, y], …], class}`                                                                                                                                      |
| `skeletons` | `{point: [[x, y], …], class}`                                                                                                                                      |

所有坐标均为原始图像的像素坐标。Model 阶段会将模型的类别映射到项目类别。

在 Agent 阶段保存时，`classes` 指项目类别，按名称和对象形状匹配，保存的对象会获得新的 ID。
