改进模型如下:
y5的模型如下:
可以看到区别是模型的 4:c3*2变成了c2*2
然后是模型的6和7去掉了。
之前的
# YOLOv5 v6.0 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 3, C2, [128]], # todo
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 6, C3, [256]],
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
[-1, 9, C3, [512]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 3, C3, [1024]],
[-1, 1, SPPF, [1024, 5]], # 9
]
# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 13
[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 17 (P3/8-small)
[-1, 1, Conv, [256, 3, 2]],
[[-1, 14], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False]], # 20 (P4/16-medium)
[-1, 1, Conv, [512, 3, 2]],
[[-1, 10], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 23 (P5/32-large)
[[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
]
改后的
# y6
# YOLOv5 v6.0 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 6, C3, [256]], #4 todo: 修改为c2*2
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 3, C3, [1024]],
[-1, 1, SPPF, [1024, 5]], # 9 todo:修改参数[-1, 1, SPPF, [1024, 5]]:层数变为7
]
# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 3, 2]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 13
[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 17 (P3/8-small)
[-1, 1, Conv, [256, 3, 2]],
[[-1, 12], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False]], # 20 (P4/16-medium)
[-1, 1, Conv, [512, 3, 2]],
[[-1, 8], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 23 (P5/32-large)
[[15, 18, 21], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
]
python train.py --img 900 --batch 2 --epoch 2 --data paper_data/ab.yaml --cfg models/yolov5s.yaml --weights yolov5s.pt
train: weights=yolov5s.pt, cfg=models/yolov5s.yaml, data=paper_data/ab.yaml, hyp=data\hyps\hyp.scratch-low.yaml, epochs=2, batch
_size=2, imgsz=900, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, noplots=False, evolve=None, bucket=
, cache=None, image_weights=False, device=, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=8, projec
t=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=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest
github: skipping check (not a git repository), for updates see https://github.com/ultralytics/yolov5
YOLOv5 2022-12-7 Python-3.9.15 torch-1.13.0+cpu CPU
hyperparameters: lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr
=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0
.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0
ClearML: run 'pip install clearml' to automatically track, visualize and remotely train YOLOv5 in ClearML
Comet: run 'pip install comet_ml' to automatically track and visualize YOLOv5 runs in Comet
TensorBoard: Start with 'tensorboard --logdir runs\train', view at http://localhost:6006/
Overriding model.yaml nc=80 with nc=4
from n params module arguments
0 -1 1 3520 models.common.Conv [3, 32, 6, 2, 2]
1 -1 1 18560 models.common.Conv [32, 64, 3, 2]
2 -1 1 18816 models.common.C3 [64, 64, 1]
3 -1 1 73984 models.common.Conv [64, 128, 3, 2]
4 -1 2 115712 models.common.C3 [128, 128, 2]
5 -1 1 590848 models.common.Conv [128, 512, 3, 2]
6 -1 1 1182720 models.common.C3 [512, 512, 1]
7 -1 1 656896 models.common.SPPF [512, 512, 5]
8 -1 1 1180160 models.common.Conv [512, 256, 3, 2]
9 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
10 [-1, 6] 1 0 models.common.Concat [1]
11 -1 1 427520 models.common.C3 [768, 256, 1, False]
12 -1 1 33024 models.common.Conv [256, 128, 1, 1]
13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
14 [-1, 4] 1 0 models.common.Concat [1]
15 -1 1 90880 models.common.C3 [256, 128, 1, False]
16 -1 1 147712 models.common.Conv [128, 128, 3, 2]
17 [-1, 12] 1 0 models.common.Concat [1]
18 -1 1 296448 models.common.C3 [256, 256, 1, False]
19 -1 1 590336 models.common.Conv [256, 256, 3, 2]
20 [-1, 8] 1 0 models.common.Concat [1]
21 -1 1 1182720 models.common.C3 [512, 512, 1, False]
22 [15, 18, 21] 1 24273 models.yolo.Detect [4, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
YOLOv5s summary: 179 layers, 6634129 parameters, 6634129 gradients, 19.4 GFLOPs
Transferred 90/289 items from yolov5s.pt
WARNING --img-size 900 must be multiple of max stride 32, updating to 928
optimizer: SGD(lr=0.01) with parameter groups 47 weight(decay=0.0), 50 weight(decay=0.0005), 50 bias
train: Scanning E:\doc\1.学院\3.学习培训\21.365深度学习训练营\y2\yolov5-master\paper_data\train... 180 images, 0 backgrounds, 0
train: WARNING Cache directory E:\doc\1.\3.\21.365\y2\yolov5-master\paper_data is not writeable: [WinError 183] : 'E:\\doc\\1.\
\3.\\21.365\\y2\\yolov5-master\\paper_data\\train.cache.npy' -> 'E:\\doc\\1.\\3.\\21.365\\y2\\yolov5-master\\paper_data\\train.cache'
val: Scanning E:\doc\1.学院\3.学习培训\21.365深度学习训练营\y2\yolov5-master\paper_data\val.cache... 20 images, 0 backgrounds,
AutoAnchor: 4.82 anchors/target, 1.000 Best Possible Recall (BPR). Current anchors are a good fit to dataset
Plotting labels to runs\train\exp27\labels.jpg...
Image sizes 928 train, 928 val
Using 2 dataloader workers
Logging results to runs\train\exp27
Starting training for 2 epochs...
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
0/1 0G 0.1104 0.06085 0.04321 9 928: 0%| | 0/90 [00:02<?, ?it/s]WARNING Te
nsorBoard graph visualization failure Sizes of tensors must match except in dimension 1. Expected size 58 but got size 57 for tensor number 1 in the list.
0/1 0G 0.1057 0.06416 0.04225 11 928: 100%|██████████| 90/90 [03:06<00:00, 2.08s/it]
Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 5/5 [00:07<00:00, 1
all 20 60 0.000126 0.0375 7.81e-05 1.72e-05
YOLOv5s summary: 132 layers, 6626161 parameters, 0 gradients, 19.2 GFLOPs
Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 5/5 [00:07<00:00, 1
YOLOv5s summary: 132 layers, 6626161 parameters, 0 gradients, 19.2 GFLOPs
Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 5/5 [00:07<00:00, 1
all 20 60 0.00197 0.194 0.00162 0.000497
banana 20 16 0.00302 0.188 0.00181 0.000712
snake fruit 20 20 0.000484 0.05 0.000313 3.13e-05
dragon fruit 20 11 0 0 0 0
pineapple 20 13 0.00439 0.538 0.00435 0.00125
Results saved to runs\train\exp27