Skip to content

zhouzq-thu/DETR-ONNX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DETR models in ONNX format

Model Zoo

Algorithm Supported Year Github Link Note
DETR 2020 Link
Deformable-DETR 2021 Link
LW-DETR 2024 Link
RT-DETR 2024 Link Use focal loss
RF-DETR 2025 Link
DEIMv2 2025 Link Use focal loss

Download weights from Release, then put them into models folder.

NOTE: The ONNX models already fused the image normalization using mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225].

Model info

The input shape of these models are dynamic (batch size and image size).

  • Inputs:
    • input: ['N', 3, 'H', 'W'] (FLOAT)
  • Outputs:
    • logits: ['N', 300, 80 or 91 or 301] (FLOAT)
    • boxes: ['N', 300, 4] (FLOAT)

Some models use focal loss instead of cross entropy loss.

You can view ONNX models with netron, which can visualize the shape of each layer.

With onnxruntime, you can use the following script to get some model infos.

import onnxruntime as ort

sess = ort.InferenceSession(model_path)
input_name = sess.get_inputs()[0].name
output_names = [output.name for output in sess.get_outputs()]
input_shape = sess.get_inputs()[0].shape
meta = sess.get_modelmeta().custom_metadata_map
stride = int(meta.get('stride', -1))
class_names = eval(meta.get('names', '{}'))

Usage

python

import cv2 as cv
from detr_onnx import DetrONNX

model_path = "models/rt-detrv2.onnx"
detr = DetrONNX(model_path)

img = cv.imread("images/kite.jpg")
prob, boxes = detr.detect(img)
res = detr.plot_result(img, prob, boxes)

cv.imshow("res", res)
cv.waitKey(0)

C++

mkdir build && cd build
cmake ../cpp
# Usage: ./build/detr_onnx <model_path> <image_path>

About

DETR models in ONNX

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors