Yolov5 知识蒸馏训练项目使用文档
1. 项目的目录结构及介绍
Yolov5-distillation-train-inference/
├── data/
│ ├── voc.yaml
│ └── scripts/
│ └── get_voc2007.sh
├── model/
│ └── yolov5l.yaml
├── weights/
│ └── yolov5l_voc.pt
├── train_distill.py
├── example.ipynb
└── README.md
data/
: 包含数据集配置文件和下载脚本。voc.yaml
: VOC数据集的配置文件。scripts/
: 包含数据集下载脚本。get_voc2007.sh
: 下载VOC2007数据集的脚本。
model/
: 包含模型配置文件。yolov5l.yaml
: YOLOv5l模型的配置文件。
weights/
: 包含预训练模型权重。yolov5l_voc.pt
: YOLOv5l模型的权重文件。
train_distill.py
: 蒸馏训练的主文件。example.ipynb
: Jupyter Notebook示例文件。README.md
: 项目说明文档。
2. 项目的启动文件介绍
train_distill.py
这是项目的主要启动文件,用于进行知识蒸馏训练。以下是该文件的主要功能和参数:
--weights
: 预训练模型的路径。--teacher
: 教师模型的权重路径。--distill_ratio
: 蒸馏损失的权重。--teacher-cfg
: 教师模型的配置文件路径。--data
: 数据集配置文件路径。--epochs
: 训练的轮数。--batch-size
: 批处理大小。
示例命令:
python train_distill.py --weights yolov5s.pt --teacher weights/yolov5l_voc.pt --distill_ratio 0.001 --teacher-cfg model/yolov5l.yaml --data data/voc.yaml --epochs 30 --batch-size 16
3. 项目的配置文件介绍
data/voc.yaml
该文件包含了VOC数据集的配置信息,包括数据集的路径、类别数等。
示例内容:
train: data/VOC2007/train.txt
val: data/VOC2007/val.txt
nc: 20
names: ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
model/yolov5l.yaml
该文件包含了YOLOv5l模型的配置信息,包括模型的结构、层数等。
示例内容:
# parameters
nc: 20 # number of classes
depth_multiple: 1.0 # model depth multiple
width_multiple: 1.0 # layer channel multiple
# anchors
anchors:
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32
# YOLOv5 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Focus, [64, 3]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, Conv, [256, 3, 2]],