在深度学习实践中,环境配置是十分重要且免不了的一步。本文以 YOLOv4 模型,介绍在Linux下虚拟环境配置到模型训练的过程。
安装Miniconda:
Miniconda是Anaconda的一个轻量级版本,非常适合用于科学计算和数据处理。
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
创建并激活Python环境:
为YOLOv4创建一个隔离的Python环境,避免依赖冲突。
conda create -n yolov4 python=3.8.8
conda activate yolov4
使用以下命令检查PyTorch是否正确安装:
import torch
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.version.cuda)
配置镜像源:
使用清华大学提供的镜像源可以加快包的下载速度。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
安装PyTorch及依赖:
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
YOLOv4的训练和测试可以通过多种方式实现,这里我们将介绍使用Darknet框架训练的方法。
YOLOv4在Darknet的源代码可以在GitHub上找到,下载地址是