YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

RF-DETR Small

This version of RF-DETR has been converted to run on the Axera NPU using u8 (INT8) quantization.

Converted with Pulsar2 version 7.0.

切分模型

模型 作用 输入 输出
rfdetr_small_512_hf_sim.onnx 切分源模型/完整 FP32 基准模型 pixel_values,FP32 NCHW logitspred_boxes
models/rfdetr_small_512_b2_pulsar2.onnx pulsar2 编译输入图 pixel_values logitsbbox_featuresreference_boxes
models/rfdetr_small_512_b2_post.onnx Host bbox 后处理图 bbox_featuresreference_boxes pred_boxes

logits 为分类输出;pred_boxes 为归一化的 cxcywh 框。B2 后处理图仅负责由中间 bbox 特征和参考框生成 pred_boxes

脚本

脚本 运行位置 作用
export_rfdetr_small_onnx_hf.py 开发机 从 Hugging Face 下载原始模型,导出并使用 onnxsim 优化固定 shape 的 ONNX。
b2_cut.py 开发机 从完整 ONNX 提取 pulsar2 输入图和 Host 后处理图。
b2_infer_onnx.py 开发机 使用 onnxruntime 运行 FP32 ONNX,保存 raw_outputs.npz 与性能数据。
b2_infer_axmodel.py AX650 使用 axengine 运行 .axmodel;指定 --post-model 时调用 Host 后处理图。
evaluate_rfdetr.py 开发机 raw_outputs.npz 转为 COCO 预测、计算 mAP,并比较两份 metrics.json

编译配置为 pulsar2_config.json,校准集使用 datasets/coco2017val_5000(项目对应dataset下只存放了示例,可自行下载coco数据集进行验证)。

结果展示

rf-detr-small.axmodel板端运行结果

 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.490
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.681
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.528
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.272
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.544
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.697
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.367
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.597
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.648
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.404
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.716
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.873

=== 正式 COCO mAP 结果 ===
原始输出: results/ax_val_5000/raw_outputs.npz
图数=5000  预测数=1499905
AP@[.5:.95]=0.4896  AP@.5=0.6810  AP@.75=0.5280
AP_small=0.2719  AP_medium=0.5441  AP_large=0.6973

rf-detr-small.axmodel板端延迟

ax_run_model -m  rf-detr-small.axmodel -r 100 -w 10
   Run AxModel:
         model: rf-detr-small.axmodel
          type: 1 Core
          vnpu: Disable
      affinity: 0b001
        warmup: 10
        repeat: 100
         batch: { auto: 0 }
      parallel: false
   pulsar2 ver: 6.0 48520c11
    engine ver: 2.12.0s
      tool ver: 2.5.1a
      cmm size: 36428267 Bytes
  ---------------------------------------------------------------------------
  min =  37.285 ms   max =  50.340 ms   avg =  39.178 ms  median =  38.649 ms
   5% =  37.313 ms   90% =  40.041 ms   95% =  40.070 ms     99% =  50.340 ms
  ---------------------------------------------------------------------------

rf-detr-small.axmodel板端运行结果

python src/tool/evaluate_rfdetr.py     --compare-metrics  \
results/onnx_fp32_5000/metrics.json     results/ax_val_5000/metrics.json   \  
--primary -metric 'AP@[0.5:0.95]'

量化精度正式对比
评测集: datasets/annotations_val2017/annotations/instances_val2017.json
图片数: 5000

metric           | baseline  | quantized | drop    
-----------------|-----------|-----------|---------
AP@0.5           | 0.709629  | 0.680995  | 0.028634
AP@0.75          | 0.564776  | 0.528006  | 0.03677 
AP@[0.5:0.95]    | 0.522527  | 0.489605  | 0.032923
AP_large         | 0.723467  | 0.697302  | 0.026165
AP_medium        | 0.575634  | 0.544072  | 0.031562
AP_small         | 0.312324  | 0.271881  | 0.040443
AR@1             | 0.382697  | 0.366594  | 0.016103
AR@10            | 0.621168  | 0.596892  | 0.024276
AR@100           | 0.672812  | 0.648423  | 0.024389
AR_large         | 0.87384   | 0.872696  | 0.001144
AR_medium        | 0.73998   | 0.715606  | 0.024374
AR_small         | 0.447414  | 0.403977  | 0.043437
prediction_count | 1499568.0 | 1499905.0 | -337.0

基本流程

# 1. 下载模型
git clone https://huggingface.co/AXERA-TECH/rf-detr-small
cd rf-detr-small

# 2. 从 Hugging Face 下载原始模型、导出并优化 ONNX
python src/tool/export_rfdetr_small_onnx_hf.py

# 3. 切分 ONNX
python /b2_cut.py \
  --input models/rfdetr_small_512_hf_sim.onnx \
  --pulsar2-output models/rfdetr_small_512_b2_pulsar2.onnx \
  --post-output models/rfdetr_small_512_b2_post.onnx

# 4. 用 pulsar2 编译 rfdetr_small_512_b2_pulsar2.onnx
#    配置:pulsar2_config.json
pulsar2 build  --target_hardware AX650 --input rfdetr_small_512_b2_pulsar2.onnx --output_dir output/ --config pulsar2_config.json 

# 5. 板端推理(脚本、模型、后处理 ONNX 与图片目录位于同级目录)
python3 b2_infer_axmodel.py \
  --axmodel rf-detr-small.axmodel --post-model rfdetr_small_512_b2_post.onnx \
  --img-dir coco2017val_5000 --result-dir results/ax

# 6. 开发机 COCO mAP 评测
python rf_detr_small/evaluate_rfdetr.py \
  --input results/b2/raw_outputs.npz \
  --ann datasets/annotations_val2017/annotations/instances_val2017.json \
  --result-dir results/onnx

# 7. 对比 FP32 与量化后的 metrics.json
python rf_detr_small/evaluate_rfdetr.py \
  --compare-metrics \
  results/onnx/metrics.json results/ax/metrics.json \
  --primary-metric 'AP@[0.5:0.95]'
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support