yolov5搭建环境_从0构建yolov5 Python环境+测试运行,搭建,的,pytorch

一、conda搭建pytorch1.6环境

参照yolov5的代码中的yolov5/requirements.txt配置环境

源文件如下:

# pip install -r requirements.txt

Cython

matplotlib>=3.2.2

numpy>=1.18.5

opencv-python>=4.1.2

pillow

# pycocotools>=2.0

PyYAML>=5.3

scipy>=1.4.1

tensorboard>=2.2

torch>=1.6.0

torchvision>=0.7.0

tqdm>=4.41.0

# Conda commands (in place of pip) ---------------------------------------------

# conda update -yn base -c defaults conda

# conda install -yc anaconda numpy opencv matplotlib tqdm pillow ipython

# conda install -yc conda-forge scikit-image pycocotools tensorboard

# conda install -yc spyder-ide spyder-line-profiler

# conda install -yc pytorch pytorch torchvision

# conda install -yc conda-forge protobuf numpy && pip install onnx==1.6.0 # https://github.com/onnx/onnx#linux-and-macos

1.conda新建环境

conda create -n yolov5 python=3.8

conda activate yolov5

2.下载源码

yolov5的作者代码:

git clone https://github.com/ultralytics/yolov5.git

2.安装额外的包和pytorch

[1]安装额外的包

pip install matplotlib tqdm opencv-python pillow PyYAML scipy tensorboard

[2]安装pytorch1.6

pytorch的包另外下载

ps:torch和torchvision的版本需要一致,否则会运行出现

RuntimeError: No such operator torchvision::nms

下面是下载的版本一致的whl文件,直接pip install torchvision会出现问题版本不一致

pytorch国外的源,直接在官网的安装命令会下载不下来。我们还是把轮子下下来安装:

pip install torch-1.6.0+cu101-cp38-cp38-linux_x86_64.whl

pip install torchvision-0.7.0+cu101-cp38-cp38-linux_x86_64.whl

[3]安装cuda

conda install cudatoolkit=10.1

[4]当前环境添加到JupyterLab中

conda install ipykernel

python -m ipykernel install --user

二、运行代码

python detect.py --source ./inference/images/ --weights yolov5s.pt --conf 0.4

yolov5搭建环境_从0构建yolov5 Python环境+测试运行,搭建,的,pytorch_第1张图片

输出的结果:

你可能感兴趣的:(yolov5搭建环境)