- 代码: https://github.com/ikuokuo/start-scaled-yolov4
Scaled-YOLOv4
- 代码: https://github.com/WongKinYiu/ScaledYOLOv4
- 论文: https://arxiv.org/abs/2011.08036
- 文章: https://alexeyab84.medium.com/scaled-yolo-v4-is-the-best-neural-network-for-object-detection-on-ms-coco-dataset-39dfa22fa982
环境准备
基础环境
- Nvidia 显卡的主机
- Ubuntu 18.04
- 系统安装,可见 制作 USB 启动盘,及系统安装
- Nvidia Driver
- 驱动安装,可见 Ubuntu 初始配置 - Nvidia 驱动
开发环境
下载并安装 Anaconda ,之后于 Terminal 执行:
# 创建 Python 虚拟环境
conda create -n scaled-yolov4 python=3.8 -y
conda activate scaled-yolov4
# 安装 PyTorch with CUDA
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=10.2 -c pytorch -y
注意:
pytorch
等版本请对照表 torch, torchvision, pythoncudatoolkit
版本请对照表 CUDA Toolkit and Compatible Driver Versionsconda
下载过慢,可尝试配置国内镜像源
下载 CUDA Toolkit ,其版本也注意对应 Nvidia 驱动版本。下一步需要。命令参考:
wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
sudo sh cuda_10.2.89_440.33.01_linux.run
注意:安装时,请手动取消驱动安装选项。
下载 mish-cuda 并安装:
# install mish-cuda, if you use different pytorch version, you could try https://github.com/thomasbrandon/mish-cuda
git clone https://github.com/JunnYu/mish-cuda
cd mish-cuda
python setup.py build install
git clone -b yolov4-large https://github.com/WongKinYiu/ScaledYOLOv4
脚本依赖
conda activate scaled-yolov4
cd start-scaled-yolov4/
pip install -r scripts/requirements.txt
模型准备
下载官方的 yolov4-p5.pt, yolov4-p6.pt, yolov4-p7.pt 权重文件到 ScaledYOLOv4/weights/
目录。
现有模型测试
准备 COCO 数据集
下载 COCO 数据集,
coco2017
├── annotations
│ ├── instances_train2017.json
│ └── instances_val2017.json
├── test2017
├── train2017
└── val2017
转成 YOLOv5 数据集结构,
export COCO_DIR=~/datasets/coco2017
export OUTPUT_DIR=~/datasets/coco2017_yolov5
# train2017 训练集
# - 图片:目录软链到 images/
# - 标注:转换存储进 labels/*.txt
# - 物体类型:全部记录进 *.names
# - 图片列表:有物体标注的记录进 *.txt, 无的进 *.txt.ignored
python scripts/coco2yolov5.py \
--coco_img_dir $COCO_DIR/train2017/ \
--coco_ann_file $COCO_DIR/annotations/instances_train2017.json \
--output_dir $OUTPUT_DIR
# val2017 验证集
# - 物体类型:依照训练集的记录,保证顺序
python scripts/coco2yolov5.py \
--coco_img_dir $COCO_DIR/val2017/ \
--coco_ann_file $COCO_DIR/annotations/instances_val2017.json \
--output_dir $OUTPUT_DIR \
--obj_names_file $OUTPUT_DIR/train2017.names
如下: