import cv2
import pathlib
from ultralytics import YOLO
import matplotlib.pyplot as plt
import openvino as ov
core = ov.Core()
det_model_path = pathlib.Path("/home/yuyue/yolov11/weights/yolo11n/yolo11n.xml")
det_ov_model = core.read_model(det_model_path)
device = "CPU"
ov_config = {}
det_compiled_model = core.compile_model(det_ov_model, device, ov_config)
det_model = YOLO(det_model_path.parent, task="detect")
if det_model.predictor is None:
custom = {"conf": 0.25, "batch": 1, "save": False, "mode": "predict"} # method defaults
args = {**det_model.overrides, **custom}
det_model.predictor = det_model._smart_load("predictor")(overrides=args, _callbacks=det_model.callbacks)
det_model.predictor.setup_model(model=det_model.model)
det_model.predictor.model.ov_compiled_model = det_compiled_model
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
res = det_model(frame)
image = res[0].plot()
print(res)
cv2.imshow("1",image)
cv2.waitKey(1)
环境配制:
pip install openvino
pip install ultralytics
ir模型转化:
网上大把🤪,不教了