https://www.cnblogs.com/itzixueba/p/18410587
from ultralytics import YOLO
from pathlib import Path
import torch,time
import openvino as ov
import cv2
model_path = Path(r"./best-Copy1_openvino_model/best-Copy1.xml")
image_path = Path( r"./00116.jpg")
yolo11 = YOLO("best-Copy1.pt", task="detect")
result = yolo11(image_path, show=True)
result[0].show()
core = ov.Core()
device = "CPU"
config = {"PERFORMANCE_HINT": "LATENCY"}
compiled_model = core.compile_model(model_path, device, config)
def ov_infer(*args):
result = compiled_model(args)
return torch.from_numpy(result[0])
yolo11.predictor.inference = ov_infer
img = cv2.imread(image_path)
result = yolo11.predict(img)
result[0].show()
time.sleep(6)