# Are object detection models supported in optimum?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%3E%5C
**Category:** 🤗Optimum\
**Created:** [June 21, 2023, 11:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119 "2023-06-21T23:57:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sak99](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@sak99](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsak99)%5C
**Post date:** [June 21, 2023, 11:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%2F1 "2023-06-21T23:57:07Z")

</div>

are object detection models supported in optimum? I don’t see any tasks defined for OD here [optimum/optimum/onnxruntime/trainer.py at main · huggingface/optimum · GitHub](https://github.com/huggingface/optimum/blob/main/optimum/onnxruntime/trainer.py#L95)

---

<div class="post-metadata">

**Author:** ![regisss](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/regisss/32/22467_2.png) [@regisss](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fregisss)%5C
**Post date:** [June 22, 2023, 7:58am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%2F2 "2023-06-22T07:58:26Z")

</div>

Hi @sak99! What is your use case (training, inference, ONNX, BetterTransformer,…)? For instance it is possible to export models like DETR to the ONNX format.

---

<div class="post-metadata">

**Author:** ![sak99](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@sak99](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsak99)%5C
**Post date:** [June 22, 2023, 8:41pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%2F3 "2023-06-22T20:41:10Z")

</div>

Hi @regisss I am looking at Faster R-CNN, YOLO, SparseRCNN

---

<div class="post-metadata">

**Author:** ![regisss](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/regisss/32/22467_2.png) [@regisss](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fregisss)%5C
**Post date:** [June 22, 2023, 9:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%2F4 "2023-06-22T21:07:06Z")

</div>

DETR and YOLOS are the only object-detection models that can be exported to ONNX with Optimum. The models you mentioned are not supported by the Transformers library so they are not by Optimum either.

---

<div class="post-metadata">

**Author:** ![chaosbasicly](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@chaosbasicly](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fchaosbasicly)%5C
**Post date:** [June 14, 2024, 3:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%2F5 "2024-06-14T03:30:01Z")

</div>

hello,i am begin learning huggingface , can u tell me how load YOLOS onnx in huggingface

---

<div class="post-metadata">

**Author:** ![regisss](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/regisss/32/22467_2.png) [@regisss](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fregisss)%5C
**Post date:** [June 14, 2024, 1:32pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%2F6 "2024-06-14T13:32:08Z")

</div>

@chaosbasicly Here is @merve’s great notebook showing how to do it with DETR: [smol-vision/Reduce\_any\_model\_to\_fp16\_using\_🤗\_Optimum\_DETR.ipynb at main · merveenoyan/smol-vision · GitHub](https://github.com/merveenoyan/smol-vision/blob/main/Reduce_any_model_to_fp16_using_%F0%9F%A4%97_Optimum_DETR.ipynb)  
It should be easy to adapt it to YOLOS. Let me know if you encounter any issues.

---

<div class="post-metadata">

**Author:** ![chaosbasicly](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@chaosbasicly](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fchaosbasicly)%5C
**Post date:** [June 15, 2024, 6:16pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%2F7 "2024-06-15T18:16:52Z")

</div>

Many thanks \<3

---

<div class="post-metadata">

**Author:** ![chaosbasicly](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@chaosbasicly](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fchaosbasicly)%5C
**Post date:** [June 21, 2024, 6:40pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fare-object-detection-models-supported-in-optimum%2F44119%2F8 "2024-06-21T18:40:21Z")

</div>

Hi regisss, thank you for your help. Currently, I’ve successfully inferred the YOLO model with ONNX, but its speed is too slow, so I want to convert it to an engine format. Do you know how to do this? I’ve tried to convert it using TensorRT 8.6.  
import tensorrt as trt  
import onnx

# Load ONNX model

onnx\_model\_path = ‘/home/chaos/Documents/ChaosAIVision/reseach/xenova.onnx’  
onnx\_model = onnx.load(onnx\_model\_path)

# Create TensorRT builder and network

EXPLICIT\_BATCH = 1 \<\< (int)(trt.NetworkDefinitionCreationFlag.EXPLICIT\_BATCH)  
builder = trt.Builder(trt.Logger(trt.Logger.WARNING))  
network = builder.create\_network(EXPLICIT\_BATCH)

# Parse ONNX model to create network definition

parser = trt.OnnxParser(network, builder.logger)  
parser.parse(onnx\_model.SerializeToString())

# Create TensorRT builder configuration

config = builder.create\_builder\_config()  
config.max\_workspace\_size = 1 \<\< 30 # Set maximum workspace size

# Build TensorRT engine

engine = builder.build\_engine(network, config)

# Save TensorRT engine to file

with open(‘your\_model.engine’, ‘wb’) as f:  
f.write(engine.serialize())

However, it encountered an error:

convert\_tensorrt.py  
[06/22/2024-01:33:04] [TRT] [W] onnx2trt\_utils.cpp:374: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.  
[06/22/2024-01:33:04] [TRT] [W] onnx2trt\_utils.cpp:400: One or more weights outside the range of INT32 was clamped  
/home/chaos/Documents/ChaosAIVision/reseach/convert\_tensorrt.py:18: DeprecationWarning: Use set\_memory\_pool\_limit instead.  
config.max\_workspace\_size = 1 \<\< 30 # Set maximum workspace size  
/home/chaos/Documents/ChaosAIVision/reseach/convert\_tensorrt.py:21: DeprecationWarning: Use build\_serialized\_network instead.  
engine = builder.build\_engine(network, config)  
[06/22/2024-01:33:04] [TRT] [E] 4: [network.cpp::validate::3047] Error Code 4: Internal Error (Network has dynamic or shape inputs, but no optimization profile has been defined.)  
Traceback (most recent call last):  
File “/home/chaos/Documents/ChaosAIVision/reseach/convert\_tensorrt.py”, line 25, in   
f.write(engine.serialize())  
AttributeError: ‘NoneType’ object has no attribute ‘serialize’

hope your answers
