关于 tao-train-deformable-detr
TAO 的 Deformable DETR 模型技能,用于 2D 目标检测的训练、评估、推理和部署。它采用可变形注意力处理多尺度特征,并提供 AutoML 训练策略及 TensorRT 部署参考。
主要功能
- 012D 目标检测
- 02可变形注意力与多尺度特征
- 03训练、评估及推理流程
- 04ONNX 导出与 TensorRT 部署
- 05AutoML 训练路由
适用场景
- 01使用 COCO 格式数据训练检测模型
- 02评估检测模型的 mAP50
- 03导出模型并生成 TensorRT 引擎
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ promptingcompany/ nv-skills --skill tao-train-deformable-detr安装后在 Claude Code 中输入/tao-train-deformable-detr确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
BENCHMARK.mdskill-card.mdskill.oms.sigevals/evals.jsonreferences/skill_info.yamlspec_template_deploy_evaluate.yamlspec_template_deploy_gen_trt_engine.yamlspec_template_deploy_inference.yamlspec_template_evaluate.yamlspec_template_export.yamlspec_template_gen_trt_engine.yamlspec_template_inference.yamlspec_template_quantize.yamlspec_template_train.yamltao-deploy-deformable-detr.mdtao-deploy-deformable-detr.skill_info.yamlschemas/evaluate.schema.jsonexport.schema.jsongen_trt_engine.schema.jsoninference.schema.jsonmanifest.jsonquantize.schema.jsontrain.schema.json详细介绍
Deformable DETR
用于 2D 目标检测的 Deformable DETR。使用可变形注意力高效处理多尺度特征。比 DINO 更轻量,且准确率具有竞争力。
使用预训练主干网络权重。设置 model.pretrained_backbone_path 以仅加载主干网络。
对于 TAO Deploy TensorRT 操作(gen_trt_engine、TensorRT evaluate 和 TensorRT inference),请先阅读 references/tao-deploy-deformable-detr.md。Deploy 规范模板位于此技能的 references/ 文件夹中,文件名前缀为 spec_template_deploy_*.yaml。
Dataclass 架构
生成的 TAO Core 架构打包在 schemas/<action>.schema.json 中,schemas/manifest.json 列出了可用操作。每个生成的架构还会根据架构顶层的 default 字段生成 references/spec_template_<action>.yaml。AutoML 启用状态通过 references/skill_info.yaml 中模型层级的 automl_enabled 声明。可运行的 AutoML 还要求 schemas/train.schema.json 和 references/spec_template_train.yaml 存在且可解析。使用打包的训练架构获取 automl_default_parameters、automl_disabled_parameters、默认值、最小值/最大值界限、枚举、选项权重、数学条件、依赖项和常用参数。不要假设运行时存在 ~/tao-core;维护者会在打包技能库之前重新生成架构/模板。
训练操作策略
此模型在模型层级启用了 AutoML。处理任何训练阶段请求之前,请先读取 references/skill_info.yaml,并根据显式的 automl_policy 值或用户的工作流请求确定本次运行的策略。将“turn off AutoML”“disable AutoML”“no HPO”或“plain training”等说法视为仅对本次运行设置 automl_policy: off;否则默认为 auto。当 automl_policy: auto、automl_enabled: true,且已打包 schemas/train.schema.json 和 references/spec_template_train.yaml 时,默认通过 tao-skill-bank:tao-run-automl 执行训练操作,并使用此模型的 skill_dir。保留工作流/应用层对数据集、规范、输出目录、GPU/平台设置、父检查点和 automl_policy 的覆盖值。仅当 automl_policy: off 或缺少打包的训练架构/模板时,才直接训练模型;若缺少架构,请说明此模型已启用 AutoML,但在生成架构之前无法运行 AutoML。
evaluate、inference、export 等非训练操作以及 Deploy 工作流仍由此模型技能处理。每次运行的 automl_policy 覆盖值不会更改模型元数据。
训练要求
- 数据集类型: object_detection
- 格式: coco、coco_raw
- 监控指标: val_mAP50
各操作的数据集要求
| 操作 | 规范键 | 来源 | 文件 | 是否为列表? |
|---|---|---|---|---|
| evaluate | dataset.test_data_sources.image_dir | eval_dataset | images.tar.gz | 否 |
| evaluate | dataset.test_data_sources.json_file | eval_dataset | annotations.json | 否 |
| export | dataset.train_data_sources | train_datasets | image_dir: images.tar.gz, json_file: annotations.json | 是 |
| export | dataset.val_data_sources | train_datasets | image_dir: images.tar.gz, json_file: annotations.json | 是 |
| gen_trt_engine | gen_trt_engine.tensorrt.calibration.cal_image_dir | calibration_dataset | images.tar.gz | 是 |
| inference | dataset.infer_data_sources.image_dir | inference_dataset | images.tar.gz | 是 |
| inference | dataset.infer_data_sources.classmap | inference_dataset | label_map.txt | 否 |
| quantize | dataset.train_data_sources | train_datasets | image_dir: images.tar.gz, json_file: annotations.json | 是 |
| quantize | dataset.val_data_sources | train_datasets | image_dir: images.tar.gz, json_file: annotations.json | 是 |
| quantize | dataset.quant_calibration_data_sources | train_datasets | image_dir: images.tar.gz, json_file: annotations.json | 否 |
| train | dataset.train_data_sources | train_datasets | image_dir: images.tar.gz, json_file: annotations.json | 是 |
| train | dataset.val_data_sources | train_datasets | image_dir: images.tar.gz, json_file: annotations.json | 是 |
常见规范覆盖项
每项操作都必须覆盖数据源——Agent 必须根据上方“各操作的数据集要求”表构建数据源路径,并将其纳入 spec_overrides。
S3_TRAIN = "s3://bucket/data/train"
S3_EVAL = "s3://bucket/data/eval"
train(必需数据源):
{
"train.num_epochs": 10,
"train.checkpoint_interval": 10,
"train.validation_interval": 10,
"train.num_gpus": 1,
"dataset.num_classes": "<num_classes> + 1",
"dataset.train_data_sources": [{"image_dir": f"{S3_TRAIN}/images.tar.gz", "json_file": f"{S3_TRAIN}/annotations.json"}],
"dataset.val_data_sources": [{"image_dir": f"{S3_TRAIN}/images.tar.gz", "json_file": f"{S3_TRAIN}/annotations.json"}],
}
evaluate(必需数据源):
{
"dataset.num_classes": "<num_classes> + 1",
"dataset.test_data_sources.image_dir": f"{S3_EVAL}/images.tar.gz",
"dataset.test_data_sources.json_file": f"{S3_EVAL}/annotations.json",
}
export(必需数据源):
{
"dataset.num_classes": "<num_classes> + 1",
"dataset.train_data_sources": [{"image_dir": f"{S3_TRAIN}/images.tar.gz", "json_file": f"{S3_TRAIN}/annotations.json"}],
"dataset.val_data_sources": [{"image_dir": f"{S3_TRAIN}/images.tar.gz", "json_file": f"{S3_TRAIN}/annotations.json"}],
}
gen_trt_engine(必需数据源):
{
"gen_trt_engine.tensorrt.data_type": "FP16",
"dataset.num_classes": "<num_classes> + 1",
"gen_trt_engine.tensorrt.calibration.cal_image_dir": [f"{S3_TRAIN}/images.tar.gz"],
}
inference(必需数据源):
{
"dataset.num_classes": "<num_classes> + 1",
"dataset.infer_data_sources.image_dir": [f"{S3_EVAL}/images.tar.gz"],
"dataset.infer_data_sources.classmap": f"{S3_EVAL}/label_map.txt",
}
quantize(必需数据源):
{
"dataset.train_data_sources": [{"image_dir": f"{S3_TRAIN}/images.tar.gz", "json_file": f"{S3_TRAIN}/annotations.json"}],
"dataset.val_data_sources": [{"image_dir": f"{S3_TRAIN}/images.tar.gz", "json_file": f"{S3_TRAIN}/annotations.json"}],
"dataset.quant_calibration_data_sources": {"image_dir": f"{S3_TRAIN}/images.tar.gz", "json_file": f"{S3_TRAIN}/annotations.json"},
}
评估数据集
可选。若提供,则会在每个检查点间隔计算验证集 mAP。
重要参数
- dataset.num_classes:目标类别数。默认值为 91(COCO)。必须与标注匹配。
- model.backbone:默认值为 resnet_50。支持:resnet_50、gcvit_tiny、gcvit_small、gcvit_base、gcvit_large、gcvit_large_384(支持范围比 DINO 更有限)。
- train.optim.lr:学习率。默认值为 2e-4(AdamW)。lr_backbone 为 2e-5。
- train.optim.lr_steps:MultiStep 学习率调度。默认值为 [40]。对于短时运行,请将其设置为总轮数的约 80%。
- model.num_queries:目标查询数量。默认值为 300。有效范围为 100-900。
- model.dropout_ratio:Transformer 层中的 Dropout。默认值为 0.3(高于 DINO 的 0.0)。对于大型数据集可调低,对于小型数据集可调高。
- model.dim_feedforward:FFN 隐藏维度。默认值为 1024(DINO 为 2048)。增大该值可提升容量,但会占用更多内存。
多 GPU / 多节点
**启动方式:**由 Lightning 管理(单个 python 进程,由 Lightning 启动工作进程)。
| 规范键 | 描述 | 默认值 |
|---|---|---|
train.num_gpus | GPU 数量 | 1 |
train.gpu_ids | GPU 设备索引 | [0] |
train.num_nodes | 节点数量 | 1 |
train.distributed_strategy | ddp 或 fsdp | ddp |
DDP/FSDP 行为与 DINO 相同。多节点运行需要编排器设置 WORLD_SIZE、NODE_RANK、MASTER_ADDR、MASTER_PORT 环境变量。
导出 / TRT 默认值
- 导出输入:640x640,opset 17
- TRT 数据类型:FP32、FP16、INT8
- TRT 工作区:1024 MB
- TRT max_batch_size:1
完整的 TAO Deploy 参考:tao-deploy-deformable-detr。
硬件
至少需要 1 个 GPU,建议使用 4 个 GPU。每个 GPU 需要 16GB 以上(V100 或 A100)显存。由于 FFN 较小,显存需求略低于 DINO。batch_size=4 可在大多数 16GB 以上显存的 GPU 上运行。
错误模式
CUDA 内存不足:减小 batch_size(4 -> 2 -> 1)。
num_select 必须小于 num_queries * num_classes:与 DINO 的约束相同。
return_interm_indices 的长度必须与 num_feature_levels 匹配:默认值为 [1,2,3,4],num_feature_levels=4。
数据集大小小于总批次大小:减小 batch_size 或 num_gpus。
Spec 参数 / 父模型推理
特定于模型的推理映射应放在此 MD 文件中,而不是 config.json 中。生成的运行器应读取本节,并在调用 create_job() 前使用 SDK 助手应用这些映射。这与旧版微服务的 infer_params.py 流程一致。
TAO Core deformable_detr.config.json 中的推理映射:
| 操作 | Spec 字段 | 推理函数 | 含义 |
|---|---|---|---|
| evaluate | encryption_key | key | 加密密钥 |
| evaluate | evaluate.checkpoint | parent_model | 从父作业结果文件夹推断出的模型文件 |
| evaluate | evaluate.trt_engine | parent_model | 从父作业结果文件夹推断出的模型文件 |
| evaluate | results_dir | output_dir | 当前作业的结果目录 |
| export | encryption_key | key | 加密密钥 |
| export | export.checkpoint | parent_model | 从父作业结果文件夹推断出的模型文件 |
| export | export.onnx_file | create_onnx_file | 输出 ONNX 路径 |
| export | results_dir | output_dir | 当前作业的结果目录 |
| gen_trt_engine | encryption_key | key | 加密密钥 |
| gen_trt_engine | gen_trt_engine.onnx_file | parent_model | 从父作业结果文件夹推断出的模型文件 |
| gen_trt_engine | gen_trt_engine.tensorrt.calibration.cal_cache_file | create_cal_cache | 校准缓存路径 |
| gen_trt_engine | gen_trt_engine.trt_engine | create_engine_file | 输出 TensorRT 引擎路径 |
| gen_trt_engine | results_dir | output_dir | 当前作业的结果目录 |
| inference | encryption_key | key | 加密密钥 |
| inference | inference.checkpoint | parent_model | 从父作业结果文件夹推断出的模型文件 |
| inference | inference.trt_engine | parent_model | 从父作业结果文件夹推断出的模型文件 |
| inference | results_dir | output_dir | 当前作业的结果目录 |
| quantize | encryption_key | key | 加密密钥 |
| quantize | quantize.model_path | parent_model | 从父作业结果文件夹推断出的模型文件 |
| quantize | results_dir | output_dir | 当前作业的结果目录 |
| train | encryption_key | key | 加密密钥 |
| train | model.pretrained_backbone_path | ptm_if_no_resume_model | 不存在恢复检查点时使用的 PTM |
| train | results_dir | output_dir | 当前作业的结果目录 |
| train | train.resume_training_checkpoint_path | resume_model | 从当前作业结果文件夹推断出的模型文件 |
对于 parent_model 或 parent_model_folder,将上游 train/export/AutoML 子作业 ID 作为 parent_job_id 传入。SDK 会列出父结果文件夹、筛选检查点产物,并返回选定的模型文件或文件夹。不要将这些映射加回 config.json,也不要修改生成的运行器脚本来猜测检查点路径。