> 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/sdks/lidar-scene-uploads.md).

# LiDAR 场景上传

使用 Unitlab Python SDK 将 LiDAR 点云、场景文件夹、zip 文件和 nuScenes 数据集作为场景上传，并跟踪处理状态、重试失败场景。

无论由什么组成，一个 LiDAR 场景就是一个工作条目：可以是一个点云、一组帧序列，或多个传感器及其相机。只有指定 `pointcloud` 类型时才会上传场景；否则 `.pcd`、`.ply` 和 `.bin` 文件会被跳过。

{% hint style="info" %}
工作区需要启用 LiDAR 场景功能。如果上传被拒绝，请联系你的 Unitlab 对接人。
{% endhint %}

## 先预览，再上传 <a href="#preview-then-upload" id="preview-then-upload"></a>

```python
from unitlab import detect_scenes

for scene in detect_scenes("./recordings").scenes:
    print(scene.name, scene.frame_count, scene.point_sensors, scene.cameras)

batch = project.upload("./recordings", generic_type="pointcloud")
batch.wait()

for item_id in batch.data_item_ids:
    status = project.scene_status(item_id)
    print(status.status, status.frame_count, status.error)
```

`detect_scenes()` 不会发送任何数据。在 CLI 中，可为 `unitlab project upload ... --type pointcloud` 加上 `--dry-run`。

## 可用的数据源 <a href="#what-a-source-can-be" id="what-a-source-can-be"></a>

| 数据源                                                     | 生成结果                                                        |
| ------------------------------------------------------- | ----------------------------------------------------------- |
| 单个 `.pcd`、`.ply` 或 `.bin` 文件                            | 单帧场景                                                        |
| 包含帧或 `scene.json` 的 `.zip`                              | 一个场景。其他 `.zip` 文件会被拒绝。                                      |
| 包含 `scene.json` 的文件夹，或单个传感器的帧（`drive_01/lidar/000.pcd`） | 一个场景。文件名匹配的图片文件夹会成为其相机（`drive_01/cam_front/000.jpg`）。       |
| 每个传感器一个子文件夹且文件名相同的文件夹                                   | 一个包含多个传感器的场景。如果每个文件夹是独立的录制，请传入 `split_sensor_folders=True`。 |
| 包含多个上述内容的文件夹                                            | 每个各生成一个场景                                                   |
| nuScenes 数据集（`samples/` 和 `v1.0-*/`）                    | 每段录制一个场景，仅包含关键帧，标定信息取自其数据表                                  |

文件夹中的其他文件不会在此次调用中上传。如需上传普通媒体，请不指定类型再次上传该文件夹。

## 限制 <a href="#limits" id="limits"></a>

| 限制项    | 值               |
| ------ | --------------- |
| 场景大小   | 20 GiB          |
| 每个场景帧数 | 1,000           |
| 用量     | 每帧计一个 Data Unit |

`UploadBatch` 中的计数以场景为单位。

## 失败的场景 <a href="#failed-scenes" id="failed-scenes"></a>

失败的场景不会出现在 `project.data_units()` 中。请用 `project.batch_queue(id).data()` 在 Batch Queue 中查找，用 `project.scene_status(item_id)` 查看原因，并在失败约一分钟后重试：

```python
project.retry_scene(item_id)
```

## 上传到资产库 <a href="#library-uploads" id="library-uploads"></a>

```python
result = client.assets.upload("./recordings", generic_type="pointcloud", folder="Lidar")
asset = result.assets[0]
status = asset.wait()        # status.frame_count, status.error
asset.retry()                # a failed scene
```

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

请通过[任务标注与 Agent Webhook](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/task-annotations-and-agent-webhooks.md) 读取和保存场景标注。对于以文件夹形式上传的场景，`release.download_files()` 会将其按原始路径写入 `<file name>/` 下。

## 相关内容 <a href="#related" id="related"></a>

[项目上传](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/project-uploads.md) · [CLI：项目与 Data Unit](https://docs.unitlab.ai/api-sdk-cli/zh/clis/cli-projects-and-data-units.md)
