无须安装CUDA,只需要有NVIDIA图形驱动即可
1. 安装Miniconda
miniconda下载地址
1.1 安装细节
- 一个对勾都不要选择
1.2 配置环境变量
在环境变量Path中添加如下变量
C:\Server\miniconda
C:\Server\miniconda\Scripts
C:\Server\miniconda\Library\bin
2. 创建虚拟环境
2.1 创建虚拟环境yolov5
conda create -n yolov5
2.2 进入虚拟环境
conda activate yolov5
- 若出现如下错误
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run$ conda init <SHELL_NAME>Currently supported shells are:- bash- fish- tcsh- xonsh- zsh- powershellSee 'conda init --help' for more information and options.IMPORTANT: You may need to close and restart your shell after running 'conda init
Windows:执行如下命令后即可使用命令conda activate yolov5
conda init cmd.exe
Linux:执行如下命令后即可使用命令conda activate yolov5
conda init bash
2.3 更换清华镜像源
清华镜像网站
3. PyTorch安装
3.1 进入pytorch官网下载v1.8.2
- 本人显卡为1650,故选择CUDA 10.2版本执行命令
3.2 网速过慢
- 使用迅雷下载文件
https://download.pytorch.org/whl/lts/1.8/cu102/torch-1.8.2%2Bcu102-cp38-cp38-win_amd64.whl
- 使用pip安装
pip install C:\torch-1.8.2+cu102-cp38-cp38-win_amd64.whl
- 执行3.1中命令(本人采用CUDA版本为10.2)
pip3 install torch==1.8.2 torchvision==0.9.2 torchaudio==0.8.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cu102
4. yolov5源码下载
4.1 github下载source
https://github.com/ultralytics/yolov5/releases/v7.0/
4.2 下载
- 使用迅雷下载红框选中的源码下载即可
- 解压至C:
4.3 修改requirments.txt
- 注释掉torch和torchvision,若不注释,会使用CPU
- numpy版本号更改1.20.3
- Pillow版本号更改为5.3.0
# YOLOv5 🚀 requirements
# Usage: pip install -r requirements.txt# Base ------------------------------------------------------------------------
gitpython
ipython # interactive notebook
matplotlib>=3.2.2
numpy==1.20.3
# numpy>=1.18.5
opencv-python>=4.1.1
Pillow==8.3.0
# Pillow>=7.1.2
psutil # system resources
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
thop>=0.1.1 # FLOPs computation
# torch>=1.7.0 # see https://pytorch.org/get-started/locally (recommended)
# torchvision>=0.8.1
tqdm>=4.64.0
# protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012# Logging ---------------------------------------------------------------------
tensorboard>=2.4.1
# clearml>=1.2.0
# comet# Plotting --------------------------------------------------------------------
pandas>=1.1.4
seaborn>=0.11.0# Export ----------------------------------------------------------------------
# coremltools>=6.0 # CoreML export
# onnx>=1.9.0 # ONNX export
# onnx-simplifier>=0.4.1 # ONNX simplifier
# nvidia-pyindex # TensorRT export
# nvidia-tensorrt # TensorRT export
# scikit-learn<=1.1.2 # CoreML quantization
# tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos)
# tensorflowjs>=3.9.0 # TF.js export
# openvino-dev # OpenVINO export# Deploy ----------------------------------------------------------------------
# tritonclient[all]~=2.24.0# Extras ----------------------------------------------------------------------
# mss # screenshots
# albumentations>=1.0.3
# pycocotools>=2.0 # COCO mAP
# roboflow
# ultralytics # HUB https://hub.ultralytics.com
4.4 下载yolov5s.pt
https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt
4.5 将yolov5s.pt放入yolov5-7.0目录下
4.6 测试
python detect.py --weights .\yolov5s.pt
- 结果
detect: weights=['.\\yolov5s.pt'], source=data\images, data=data\coco128.yaml, imgsz=[640, 640], conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs\detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False, dnn=False, vid_stride=1
YOLOv5 2022-11-22 Python-3.8.18 torch-1.8.2+cu102 CUDA:0 (NVIDIA GeForce GTX 1650, 4096MiB)Fusing layers...
YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs
image 1/2 C:\WorkSpace\OpenCV\yolov5-7.0\data\images\bus.jpg: 640x480 4 persons, 1 bus, 14.0ms
image 2/2 C:\WorkSpace\OpenCV\yolov5-7.0\data\images\zidane.jpg: 384x640 2 persons, 2 ties, 11.0ms
Speed: 1.0ms pre-process, 12.5ms inference, 3.5ms NMS per image at shape (1, 3, 640, 640)
Results saved to runs\detect\exp2