RT-DETR环境搭建&推理测试

引子

        作为YOLO的拥趸,之前一直没有太关注DETR,虽然知道效果很好。但是,巨大的计算开销,还是一直让我望而却步。然而,今天在翻阅CVPR2024的论文的时候,突然看到这么一篇《RT-DETR: DETRs Beat YOLOs on Real-time Object Detection》。嗯,它成功的引起了我的注意。

        百度的这篇文章首先分析了现代实时目标检测器中NMS对推理速度的影响,并建立了端到端的速度基准。为了避免NMS引起的推理延迟,作者提出了一种实时检测Transformer(RT-DETR),这是第一个实时DERT端到端目标检测器。具体而言,设计了一种高效的混合编码器,通过解耦尺度内交互和跨尺度融合来高效处理多尺度特征,并提出了IoU感知的查询选择,以提高目标查询的初始化。此外,本文提出的检测器支持通过使用不同的解码器层来灵活调整推理速度,而不需要重新训练,这有助于实时目标检测器的实际应用。OK,让我们开始吧。

一、环境安装

1、代码仓库

GitHub - lyuwenyu/RT-DETR: [CVPR 2024] Official RT-DETR (RTDETR paddle pytorch), Real-Time DEtection TRansformer, DETRs Beat YOLOs on Real-time Object Detection. 🔥 🔥 🔥

git clone GitHub - lyuwenyu/RT-DETR: [CVPR 2024] Official RT-DETR (RTDETR paddle pytorch), Real-Time DEtection TRansformer, DETRs Beat YOLOs on Real-time Object Detection. 🔥 🔥 🔥

2、安装依赖

docker pull registry.baidubce.com/paddlepaddle/paddle:2.6.0-gpu-cuda11.2-cudnn8.2-trt8.0

docker run -it --gpus="1" --rm -v /datas/work/zzq/:/workspace 008c70104913 bash

cd /workspace/RT-DETR/RT-DETR

pip install -r requirements.txt -i -i Simple Index

3、模型下载

RT-DETR/rtdetr_paddle at main · lyuwenyu/RT-DETR · GitHub

二、测试

1、训练

# training on single-gpu

export CUDA_VISIBLE_DEVICES=0

python tools/train.py -c configs/rtdetr/rtdetr_r50vd_6x_coco.yml

# train on multi-gpu

export CUDA_VISIBLE_DEVICES=0,1,2,3

torchrun --nproc_per_node=4 tools/train.py -c configs/rtdetr/rtdetr_r50vd_6x_coco.yml

2、推理

python tools/infer.py -c configs/rtdetr/rtdetr_r18vd_6x_coco.yml -o weights=./model/rtdetr_r18vd_dec3_6x_coco.pdparams --infer_img=./images/20231102192534.png

3、导出转换

(1)导出静态模型

修改代码

rtdetr_paddle/ppdet/engine/trainer.py 932行

python tools/export_model.py -c configs/rtdetr/rtdetr_r18vd_6x_coco.yml -o weights=./model/rtdetr_r18vd_dec3_6x_coco.pdparams --output_dir=output_inference

(2)转ONNX

pip install onnx==1.13.0 -i Simple Index

pip install paddle2onnx==1.0.5 -i Simple Index

paddle2onnx --model_dir=./output_inference/rtdetr_r18vd_6x_coco/ --model_filename model.pdmodel --params_filename model.pdiparams --opset_version 16 --save_file rtdetr_r18vd_6x_coco.onnx

  • 13
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

要养家的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值