EfficientDet (TF2) 与 TAO Deploy
从 export
生成的 TF2 EfficientDet ONNX 模型被用作 tao deploy
的输入,以生成优化的 TensorRT 引擎。有关训练 TF2 EfficientDet 的更多信息,请参阅 TF2 EfficientDet 训练文档。
相同的 spec 文件可以与 tao model efficientdet_tf2 export
命令一起使用。
GenTrtEngine 配置
gen_trt_engine
配置包含将 .onnx
模型导出到 TensorRT 引擎的参数,该引擎可用于部署。
字段 | 描述 | 数据类型和约束 | 推荐/典型值 |
onnx_file | 导出的 .onnx 模型的路径 | string | |
trt_engine | 将存储生成的引擎的路径 | string | |
results_dir | 用于保存输出日志的目录。如果未指定,日志将保存在全局 $results_dir/gen_trt_engine 下 | string | |
tensorrt | TensorRT 配置 | Dict |
tensorrt
配置包含 TensorRT 引擎和校准要求的规范。 +——————————+———————————————————————-+——————————-+——————————-+ | 字段 | 描述 | 数据类型和约束 | 推荐/典型值 | +——————————+———————————————————————-+——————————-+——————————-+ | data_type | 用于 TensorRT 引擎的精度 | string | FP32 | +——————————+———————————————————————-+——————————-+——————————-+ | min_batch_size | 用于优化配置文件形状的最小批次大小 | unsigned int | 1 | +——————————+———————————————————————-+——————————-+——————————-+ | opt_batch_size | 用于优化配置文件形状的最佳批次大小 | unsigned int | 1 | +——————————+———————————————————————-+——————————-+——————————-+ | max_batch_size | 用于优化配置文件形状的最大批次大小 | unsigned int | 1 | +——————————+———————————————————————-+——————————-+——————————-+ | max_workspace_size | TensorRT 引擎的最大工作区大小 | unsigned int | 2 | +——————————+———————————————————————-+——————————-+——————————-+ | calibration | 校准配置 | Dict | | +——————————+———————————————————————-+——————————-+——————————-+
calibration
配置指定校准数据的位置以及校准缓存文件的保存位置。 +——————————+———————————————————————-+——————————-+——————————-+ | 字段 | 描述 | 数据类型和约束 | 推荐/典型值 | +——————————+———————————————————————-+——————————-+——————————-+ | cal_image_dir | 包含用于校准的图像的目录 | string | False | +——————————+———————————————————————-+——————————-+——————————-+ | cal_cache_file | 校准缓存文件的路径 | string | False | +——————————+———————————————————————-+——————————-+——————————-+ | cal_batches | 用于校准的迭代批次数 | unsigned int | 10 | +——————————+———————————————————————-+——————————-+——————————-+ | cal_batch_size | 每个批次的批次大小 | unsigned int | 1 | +——————————+———————————————————————-+——————————-+——————————-+
以下是 TF2 EfficientDet 的示例 spec 文件。
dataset:
augmentation:
rand_hflip: True
random_crop_min_scale: 0.1
random_crop_max_scale: 2
loader:
prefetch_size: 4
shuffle_file: False
shuffle_buffer: 10000
cycle_length: 32
block_length: 16
max_instances_per_image: 100
skip_crowd_during_training: True
num_classes: 91
train_tfrecords:
- '/data/train-*'
val_tfrecords:
- '/data/val-*'
val_json_file: '/data/annotations/instances_val2017.json'
train:
optimizer:
name: 'sgd'
momentum: 0.9
lr_schedule:
name: 'cosine'
warmup_epoch: 5
warmup_init: 0.0001
learning_rate: 0.2
amp: True
checkpoint: ''
num_examples_per_epoch: 100
moving_average_decay: 0.999
batch_size: 20
checkpoint_interval: 5
l2_weight_decay: 0.00004
l1_weight_decay: 0.0
clip_gradients_norm: 10.0
image_preview: True
qat: False
random_seed: 42
pruned_model_path: ''
num_epochs: 20
model:
name: 'efficientdet-d0'
input_width: 512
input_height: 512
aspect_ratios: '[(1.0, 1.0), (1.4, 0.7), (0.7, 1.4)]'
anchor_scale: 4
min_level: 3
max_level: 7
num_scales: 3
freeze_bn: False
freeze_blocks: []
evaluate:
batch_size: 8
num_samples: 500
max_detections_per_image: 100
label_map: "/data/coco_labels.yaml"
trt_engine: "/output/efficientdet-d0.fp32.engine"
checkpoint: '/weights/efficientdet-d0_100.tlt'
export:
batch_size: 1
dynamic_batch_size: True
min_score_thresh: 0.4
checkpoint: '/weights/efficientdet-d0_100.tlt'
onnx_file: "/output/efficientdet-d0.onnx"
gen_trt_engine:
onnx_file: "/output/efficientdet-d0.onnx"
trt_engine: "/output/efficientdet-d0.fp32.engine"
tensorrt:
data_type: "fp32"
max_workspace_size: 2 # in Gb
calibration:
cal_image_dir: "/data/raw-data/val2017"
cal_cache_file: "EXPORTDIR/efficientdet-d0.cal"
cal_batch_size: 16
cal_batches: 10
inference:
checkpoint: '/weights/efficientdet-d0_100.tlt'
trt_engine: "/output/efficientdet-d0.fp32.engine"
image_dir: "/data/test_samples"
dump_label: False
batch_size: 1
min_score_thresh: 0.4
label_map: "/data/coco_labels.yaml"
results_dir: '/results'
使用以下命令运行 TF2 EfficientDet 引擎生成
tao deploy efficientdet_tf2 gen_trt_engine -e /path/to/spec.yaml \
export.onnx_path=/path/to/onnx/file \
export.trt_engine=/path/to/engine/file \
export.tensorrt.data_type=<data_type>
必需参数
-e, --experiment_spec
: 用于设置 TensorRT 引擎生成的实验 spec 文件。这应与导出规范文件相同。
可选参数
-h, --help
: 显示此帮助消息并退出。results_dir
: 全局结果目录,其中实验输出和日志将写入<task>
子目录下。
示例用法
以下是使用 gen_trt_engine
命令生成 INT8 TensorRT 引擎的示例
tao deploy efficientdet_tf2 gen_trt_engine -e $DEFAULT_SPEC
export.onnx_path=$ETLT_FILE \
export.trt_engine=$ENGINE_FILE \
export.tensorrt.data_type=fp16
与 TAO 评估 spec 文件相同的 spec 文件。
使用以下命令运行 TF2 EfficientDet 引擎评估
tao deploy efficientdet_tf2 evaluate -e /path/to/spec.yaml
必需参数
-e, --experiment_spec
: 用于评估的实验 spec 文件。这应与 tao evaluate 规范文件相同。
可选参数
-h, --help
: 显示此帮助消息并退出。results_dir
: 全局结果目录,其中实验输出和日志将写入<task>
子目录下。
示例用法
以下是使用 evaluate
命令通过 TensorRT 引擎运行评估的示例
tao deploy efficientdet_tf2 evaluate -e $DEFAULT_SPEC
evaluate.trt_engine=$ENGINE_FILE \
evaluate.results_dir=$RESULTS_DIR
与 TAO 推理 spec 文件相同的 spec 文件。
使用以下命令运行 TF2 EfficientDet 引擎推理
tao deploy efficientdet_tf2 inference -e /path/to/spec.yaml \
inference.trt_engine=/path/to/engine/file \
inference.results_dir=/path/to/outputs
必需参数
-e, --experiment_spec
: 用于推理的实验 spec 文件。这应与 tao inference 规范文件相同。
可选参数
-h, --help
: 显示此帮助消息并退出。results_dir
: 全局结果目录,其中实验输出和日志将写入<task>
子目录下。
示例用法
以下是使用 inference
命令通过 TensorRT 引擎运行推理的示例
tao deploy efficientdet_tf2 inference -e $DEFAULT_SPEC
inference.trt_engine=$ENGINE_FILE \
inference.results_dir=$RESULTS_DIR
可视化将存储在 $RESULTS_DIR/images_annotated
下,KITTI 格式的预测将存储在 $RESULTS_DIR/labels
下。