You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Scalabel处理自定义图片生成单图独立JSON并转BDD100k格式?

用Scalabel生成单图独立JSON文件

Scalabel默认导出包含所有图片标注的汇总JSON,要生成单图对应独立JSON,需手动拆分汇总文件,具体步骤如下:

  1. 导出汇总标注文件
    在Scalabel标注界面完成所有标注后,导出标准Scalabel格式的JSON文件(比如命名为all_annotations.json)。

  2. 编写Python脚本拆分文件
    创建Python脚本读取汇总JSON,遍历每张图片的标注数据,生成独立JSON文件。示例代码:

import json
import os

# 读取汇总标注文件
with open('all_annotations.json', 'r') as f:
    data = json.load(f)

# 创建输出目录
output_dir = 'single_image_annotations'
os.makedirs(output_dir, exist_ok=True)

# 遍历每个图片的标注数据
for frame in data['frames']:
    # 生成对应JSON文件名(替换图片后缀为.json)
    img_base = os.path.splitext(frame['name'])[0]
    json_path = os.path.join(output_dir, f'{img_base}.json')
    
    # 构造单图标注结构(保留核心字段)
    single_anno = {
        'name': frame['name'],
        'timestamp': frame.get('timestamp', 0),
        'labels': frame.get('labels', []),
        'attributes': frame.get('attributes', {})
    }
    
    # 写入独立JSON文件
    with open(json_path, 'w') as out_f:
        json.dump(single_anno, out_f, indent=2)

运行脚本后,single_image_annotations目录下会生成每张图片对应的独立JSON文件,每个文件仅包含该图片的标注信息。

Scalabel转BDD100k格式方法

Scalabel官方提供格式转换工具,可直接将Scalabel标注转为BDD100k格式,操作步骤如下:

  1. 安装Scalabel命令行工具
    若未安装,通过pip完成安装:
pip install scalabel
  1. 执行转换命令
    使用scalabel convert命令,指定输入文件、输出目录和目标格式:
scalabel convert --input all_annotations.json --output bdd100k_output --format bdd100k

执行完成后,bdd100k_output目录下会生成符合BDD100k规范的标注文件(若原始数据有训练/验证集划分,会自动生成对应子目录)。

  1. 自定义字段映射(可选)
    若标注包含自定义类别或特殊属性,官方转换脚本可能无法完全匹配,可修改转换逻辑:
  • 找到Scalabel转换工具源码(通常在scalabel/format/converter.py)
  • 调整scalabel_to_bdd100k函数中的字段映射规则,比如自定义类别对应关系、属性转换逻辑等。

内容的提问来源于stack exchange,提问作者Aaron Francis Pacardo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 20:40:11