微信公众号:OpenCV学堂
关注获取更多计算机视觉与深度学习知识
Pytorch Hub介绍
YOLOv5支持
首先需要安装下面的依赖包支持
pip install -r https://raw.githubusercontent.com/ultralytics/yolov5/master/requirements.txt
相关源码贴图如下:
import torch
import cv2 as cv
# load image data
img = "data/images/zidane.jpg"
# 加载本地预训练模型
model = torch.hub.load(repo_or_dir='D:/python/yolov5-7.0-attention/', model='yolov5s', source='local')
# load image
# img = "D:/bird_test/test004.png"
# 加载本地自定义模型
# model = torch.hub.load('D:/python/yolov5-7.0-attention/', 'custom', path='uav_bird.pt', source='local')
results = model(img)
# 显示
frame = results.render()[0]
bgr = cv.cvtColor(frame, cv.COLOR_RGB2BGR)
cv.imshow("Pytorch Hub + YOLOv5 Custom Object Detection", bgr)
cv.waitKey(0)
扫码查看OpenCV+OpenVIO+Pytorch系统化学习路线图
文章引用微信公众号"OpenCV学堂",如有侵权,请联系管理员删除!