How to convert YOLO's CLS or OBB model to an OpenVINO model

from ultralytics import YOLO
import os
import sys
model_path = “punch_obb.pt”

Export the model

model.export(format=“openvino”)

I use the code to export a punch_openvion_model, but the result model end to error when using to detect ,how to export correctly?

  1. Please share the error message, as it’s very difficult to help without the details of the error, see this post and this post for some helpful guidelines for helping others help you.
  2. Can you please run the following terminal commands in your Python environment:
yolo checks

and then

pip show openvino

then post the output from both?

Something else you might want to consider trying out as a test, is exporting a pretrained model:

from ultralytics import YOLO

model = YOLO("yolo11n-obb.pt")
ov_path = model.export(format="openvino")

if this works, then it’s likely an issue with the model weights you’re using. The error message when exporting your "punch_obb.pt" model will be critical to help any further.

I just want to how to transform yolo11-obb.pt to openvino model,error model may be imgsz error ,but the example is simple,and i don not know how to transform,nobody other counter by such problems?I mean yolo’s export example has just work in detecting issue,not in obb,or in seg

u never test export(“openvino”) in obb or seg trained pt model?that’s funny.

Before I replied I tested on my local machine:

yolo export model=yolo11n-obb.pt format=openvino

That worked without issue. That’s why I asked you to test it on your machine.

Additionally, the openvino export is tested with all tasks in the CI tests here

Ultralytics CI

i know that”s ok, that”s no problem,and then ?are u sure the exported model like cls-openvino-model can be used in yolo’s detecting code? Using cls-openvino-model to judge what kind of the image is always incompatible and caused error, u can try. It always print “ imgsz not trained size like balabalab…”.Y success only in detect kind pt,not in obb, not in seg

(.ultra) PS Q:\ML_dev\ultra_pip> yolo predict model="Q:\ML_dev\ultra_repo\ultralytics-1\weights\yolo11n-obb_openvino_model\"
WARNING 'source' argument is missing. 

Using default 'source=https://ultralytics.com/images/boats.jpg'.
Ultralytics 8.3.147  Python-3.11.6 torch-2.6.0+cpu CPU (Intel Core(TM) i5-10600K 4.10GHz)
Loading Q:\ML_dev\ultra_repo\ultralytics-1\weights\yolo11n-obb_openvino_model for OpenVINO inference...
Using OpenVINO LATENCY mode for batch=1 inference...

Found https://ultralytics.com/images/boats.jpg locally at boats.jpg
image 1/1 Q:\ML_dev\ultra_pip\boats.jpg: 1024x1024 None110.5ms
Speed: 7.3ms preprocess, 110.5ms inference, 54.1ms postprocess per image at shape (1, 3, 1024, 1024)

Results saved to Q:\ML_dev\ultra_repo\ultralytics-1\runs\obb\predict2
 Learn more at https://docs.ultralytics.com/modes/predict

if i use 2000x2000pixels image as mataset and use yolo11-obb.pt as base,then out pt model as A_obb.pt,then export to openvino model as A_obb_openvino_model.Using A_obb_openvino_model to detect my 2000x2000pixels image will not work. And error may be “The input tensor size is not equal to the model input type: got [1,3,640,640] expecting [1,3,1024,1024].”
[/quote]

just use the code


use my trained A_obb.pt to replace yolo11n.pt

Try including imgsz=1024 when you call prediction:

from ultralytics import YOLO, ASSETS

image = ASSETS / "bus.jpg"
ov_model= YOLO("A_obb_openvino_model")

results = ov_model.predict(img, imgsz=1024)

it do work! tks. And i saw an suggested cli command “yolo export model=yolov8s-obb.pt imgsz=640 format=onnx dynamic=True” in onnx exporting , is there a likelihood value named dynamic in openvino exporting ?

Glad it worked! I did not use the dynamic argument when I did the export, but you can use it if that’s functionality you’d like to include.

There occuring another issue. After using the classification model (cls), I exported it to an OpenVINO model and then performed image classification. The following error occurred.‘’ line 250, in non_max_suppression
xc = prediction[:, 4:mi].amax(1) > conf_thres # candidates
^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: amax(): Expected reduction dim 1 to have non-zero size”

I forgot to mention, and include in my example, you probably need to include the task argument when loading your model. See this issue for more info:

So the example from before should be:

from ultralytics import YOLO, ASSETS

image = ASSETS / "bus.jpg"
- ov_model= YOLO("A_obb_openvino_model")
+ov_model= YOLO("A_obb_openvino_model", task="obb")

results = ov_model.predict(img, imgsz=1024)