mcpField
T
tao-train-deformable-detr

tao-train-deformable-detr

github.com/promptingcompany数据与数据库039 次安装17 周前更新
代码仓库

关于 tao-train-deformable-detr

TAO 的 Deformable DETR 模型技能,用于 2D 目标检测的训练、评估、推理和部署。它采用可变形注意力处理多尺度特征,并提供 AutoML 训练策略及 TensorRT 部署参考。

主要功能

  1. 012D 目标检测
  2. 02可变形注意力与多尺度特征
  3. 03训练、评估及推理流程
  4. 04ONNX 导出与 TensorRT 部署
  5. 05AutoML 训练路由

适用场景

  1. 01使用 COCO 格式数据训练检测模型
  2. 02评估检测模型的 mAP50
  3. 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.md
skill-card.md
skill.oms.sig
evals/
evals.json
references/
skill_info.yaml
spec_template_deploy_evaluate.yaml
spec_template_deploy_gen_trt_engine.yaml
spec_template_deploy_inference.yaml
spec_template_evaluate.yaml
spec_template_export.yaml
spec_template_gen_trt_engine.yaml
spec_template_inference.yaml
spec_template_quantize.yaml
spec_template_train.yaml
tao-deploy-deformable-detr.md
tao-deploy-deformable-detr.skill_info.yaml
schemas/
evaluate.schema.json
export.schema.json
gen_trt_engine.schema.json
inference.schema.json
manifest.json
quantize.schema.json
train.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
各操作的数据集要求
操作规范键来源文件是否为列表?
evaluatedataset.test_data_sources.image_direval_datasetimages.tar.gz否
evaluatedataset.test_data_sources.json_fileeval_datasetannotations.json否
exportdataset.train_data_sourcestrain_datasetsimage_dir: images.tar.gz, json_file: annotations.json是
exportdataset.val_data_sourcestrain_datasetsimage_dir: images.tar.gz, json_file: annotations.json是
gen_trt_enginegen_trt_engine.tensorrt.calibration.cal_image_dircalibration_datasetimages.tar.gz是
inferencedataset.infer_data_sources.image_dirinference_datasetimages.tar.gz是
inferencedataset.infer_data_sources.classmapinference_datasetlabel_map.txt否
quantizedataset.train_data_sourcestrain_datasetsimage_dir: images.tar.gz, json_file: annotations.json是
quantizedataset.val_data_sourcestrain_datasetsimage_dir: images.tar.gz, json_file: annotations.json是
quantizedataset.quant_calibration_data_sourcestrain_datasetsimage_dir: images.tar.gz, json_file: annotations.json否
traindataset.train_data_sourcestrain_datasetsimage_dir: images.tar.gz, json_file: annotations.json是
traindataset.val_data_sourcestrain_datasetsimage_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_gpusGPU 数量1
train.gpu_idsGPU 设备索引[0]
train.num_nodes节点数量1
train.distributed_strategyddp 或 fsdpddp

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 字段推理函数含义
evaluateencryption_keykey加密密钥
evaluateevaluate.checkpointparent_model从父作业结果文件夹推断出的模型文件
evaluateevaluate.trt_engineparent_model从父作业结果文件夹推断出的模型文件
evaluateresults_diroutput_dir当前作业的结果目录
exportencryption_keykey加密密钥
exportexport.checkpointparent_model从父作业结果文件夹推断出的模型文件
exportexport.onnx_filecreate_onnx_file输出 ONNX 路径
exportresults_diroutput_dir当前作业的结果目录
gen_trt_engineencryption_keykey加密密钥
gen_trt_enginegen_trt_engine.onnx_fileparent_model从父作业结果文件夹推断出的模型文件
gen_trt_enginegen_trt_engine.tensorrt.calibration.cal_cache_filecreate_cal_cache校准缓存路径
gen_trt_enginegen_trt_engine.trt_enginecreate_engine_file输出 TensorRT 引擎路径
gen_trt_engineresults_diroutput_dir当前作业的结果目录
inferenceencryption_keykey加密密钥
inferenceinference.checkpointparent_model从父作业结果文件夹推断出的模型文件
inferenceinference.trt_engineparent_model从父作业结果文件夹推断出的模型文件
inferenceresults_diroutput_dir当前作业的结果目录
quantizeencryption_keykey加密密钥
quantizequantize.model_pathparent_model从父作业结果文件夹推断出的模型文件
quantizeresults_diroutput_dir当前作业的结果目录
trainencryption_keykey加密密钥
trainmodel.pretrained_backbone_pathptm_if_no_resume_model不存在恢复检查点时使用的 PTM
trainresults_diroutput_dir当前作业的结果目录
traintrain.resume_training_checkpoint_pathresume_model从当前作业结果文件夹推断出的模型文件

对于 parent_model 或 parent_model_folder,将上游 train/export/AutoML 子作业 ID 作为 parent_job_id 传入。SDK 会列出父结果文件夹、筛选检查点产物,并返回选定的模型文件或文件夹。不要将这些映射加回 config.json,也不要修改生成的运行器脚本来猜测检查点路径。

评论

支持 Markdown