- 前言
生产应用中经常会碰到训练好的模型需要加入新的数据集的,数据量小还好说,当数据量大了就会抓瞎,太慢了。本文介绍在已有的模型基础上增强训练。
.
├── F1_curve.png
├── PR_curve.png
├── P_curve.png
├── R_curve.png
├── confusion_matrix.png
├── hyp.yaml
├── labels.jpg
├── labels_correlogram.jpg
├── opt.yaml
├── results.csv
├── results.png
├── train_batch0.jpg
├── train_batch1.jpg
├── train_batch2.jpg
├── val_batch0_labels.jpg
├── val_batch0_pred.jpg
└── weights├── best.onnx├── best.pt└── last.pt
这个是训练后得到的目录
更改opt.yaml文件
这是一个opt.yaml文件的例子
weights: yolov5s.pt
cfg: ''
data: ./data/special.yaml
hyp:lr0: 0.01lrf: 0.01momentum: 0.937weight_decay: 0.0005warmup_epochs: 3.0warmup_momentum: 0.8warmup_bias_lr: 0.1box: 0.05cls: 0.5cls_pw: 1.0obj: 1.0obj_pw: 1.0iou_t: 0.2anchor_t: 4.0fl_gamma: 0.0hsv_h: 0.015hsv_s: 0.7hsv_v: 0.4degrees: 0.0translate: 0.1scale: 0.5shear: 0.0perspective: 0.0flipud: 0.0fliplr: 0.5mosaic: 1.0mixup: 0.0copy_paste: 0.0
epochs: 600
batch_size: 64
imgsz: 640
rect: false
resume: false
nosave: false
noval: false
noautoanchor: false
noplots: false
evolve: null
evolve_population: data/hyps
resume_evolve: null
bucket: ''
cache: null
image_weights: false
device: ''
multi_scale: false
single_cls: false
optimizer: SGD
sync_bn: false
workers: 8
project: runs/train
name: exp
exist_ok: false
quad: false
cos_lr: false
label_smoothing: 0.0
patience: 100
freeze:
- 0
save_period: -1
seed: 0
local_rank: -1
entity: null
upload_dataset: false
bbox_interval: -1
artifact_alias: latest
ndjson_console: false
ndjson_file: false
save_dir: runs/train/exp12
- 将epochs改为你要训练的总轮数
- 在train.py中将resume参数的default设定为True
- 在yolov5\utils下的torch_utils.py中将start_epoch改为上次训练的轮次+1(可以在exp中的result表里看见上次最后训练的轮次,此处轮次指的是标号,自0开始的第一列中最后一行数字)
参考了 https://blog.csdn.net/m0_57041719/article/details/135467873?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_utm_term~default-4-135467873-blog-121215172.235^v43^pc_blog_bottom_relevance_base4&spm=1001.2101.3001.4242.3&utm_relevant_index=6