Pytorch入门教程-Yolov5安装
Pytorch入门教程-Yolov5安装
说明:
- 介绍如何安装和使用Yolov5
步骤:
- 编译和安装Yolov5
mkdir ~/dl
cd dl
python3 -m venv venv
source venv/bin/actavite
git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install
- 测试推理
- 新建文件
touch exmaple_inference.py
- 内容如下:
import torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5n - yolov5x6, custom
# Images
img = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, PIL, OpenCV, numpy, list
# Inference
results = model(img)
# Results
results.print() # or .show(), .save(), .crop(), .pandas(), etc.
results.show()
- 执行
python3 exmaple_inference.py
- 完成后弹出一张图片,标注了识别物体的百分比
- 效果图:
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号