OpenVINO部署YOLOv5——Python版本

  • 9
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
要在OpenVINO部署Yolov5,您需要完成以下步骤: 1. 下载Yolov5模型。您可以从GitHub上下载Yolov5模型,该模型是用Python训练的,具有.pt扩展名。 2. 将Yolov5模型转换为OpenVINO格式。使用OpenVINO的Model Optimizer工具将Yolov5模型转换为OpenVINO格式。您可以使用以下命令转换模型: ``` python3 mo.py --input_model yolov5s.pt --transformations_config yolov5.json --output_dir yolov5/ --model_name yolov5s ``` 3. 在OpenVINO上运行Yolov5模型。您可以使用以下Python代码在OpenVINO上运行Yolov5模型: ``` import cv2 import numpy as np from openvino.inference_engine import IECore # 加载OpenVINO模型 ie = IECore() net = ie.read_network(model='yolov5s.xml', weights='yolov5s.bin') exec_net = ie.load_network(network=net, device_name='CPU', num_requests=1) # 加载图像 image = cv2.imread('image.jpg') # 预处理图像 input_blob = next(iter(net.input_info)) n, c, h, w = net.input_info[input_blob].input_data.shape image = cv2.resize(image, (w, h)) image = image.transpose((2, 0, 1)) # HWC -> CHW image = image.reshape((n, c, h, w)) # 推理 outputs = exec_net.infer(inputs={input_blob: image}) # 后处理 output_blob = next(iter(net.outputs)) detections = outputs[output_blob][0][0] for detection in detections: if detection[4] > 0.5: x1 = int(detection[0] * image.shape[3]) y1 = int(detection[1] * image.shape[2]) x2 = int(detection[2] * image.shape[3]) y2 = int(detection[3] * image.shape[2]) cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2) # 显示结果 cv2.imshow('Image', image) cv2.waitKey(0) cv2.destroyAllWindows() ``` 这就是在OpenVINO部署Yolov5的步骤。请注意,您需要使用适当的硬件和驱动程序来运行OpenVINO

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值