引言
前面介绍了yolov5训练自定义的数据集,对于训练环境的配置粗略带过,于是这篇博客整理下环境搭建的详细步骤(笔者在Windows下成功搭建并训练,Ubuntu下还未尝试,有成功搭建的欢迎在评论区分享)。
一、创建一个python3.7的环境并打开
conda create -n name python=3.7 #name自己改
conda activate name
二、在虚拟环境安装cuda和cudnn和安装各种库
conda install cudatoolkit=10.2.89 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/
conda install cudnn==7.6.5 -c https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
安装依赖库:
pip install numpy==1.19.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tensorboard -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyyaml -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install Cython -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
三、安装pytorch
pip install torch===1.6.0 torchvision===0.7.0 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.douban.com/simple
特别注意:cuda和pytorch之间的版本需要相互对应(根据个人需要,笔者这里的对应版本可以成功运行)
四、下载YOLOV5模型和源码(3.1版本)
源码和权重文件:https://github.com/ultralytics/yolov5/releases/tag/v3.1
将权重文件解压到源码里。
五、安装pycocotools库(需安装visual studio)
git clone https://github.com/cocodataset/cocoapi.git(也可以在官网下载)
cd cocoapi/PythonAPI
python setup.py build_ext --inplace
python setup.py build_ext install
然后将pycocotool文件夹复制到源码文件夹中
六、测试环境
进入源码夹,输入:python detect.py
没问题,则搭建成功。