第5回は画像処理に有効な深層学習モデルを扱う。
!cp kaggle.json /root/.kaggle/ !chmod 600 /root/.kaggle/kaggle.json
!kaggle competitions download -c dogs-vs-cats
DIR="/content/tmp" !mkdir $DIR %cd $DIR !git clone https://github.com/ultralytics/yolov5 %cd yolov5 !pip install -qr requirements.txt !wget https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip !unzip coco128.zip !python train.py --img 640 --batch 16 --epochs 300 --data coco128.yaml --weights yolov5x.pt
train: weights=yolov5x.pt, cfg=, data=coco128.yaml, hyp=data/hyps/hyp.scratch-low.yaml, epochs=300, batch_size=16, imgsz=640, 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, 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=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest
github: up to date with https://github.com/ultralytics/yolov5 ✅
YOLOv5 🚀 v7.0-66-g9650f16 Python-3.8.16 torch-1.13.0+cu116 CUDA:0 (Tesla T4, 15110MiB)
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/
Dataset not found ⚠️, missing paths ['/content/tmp/datasets/coco128/images/train2017']
Downloading https://ultralytics.com/assets/coco128.zip to coco128.zip...
100% 6.66M/6.66M [00:00<00:00, 203MB/s]
Dataset download success ✅ (0.5s), saved to /content/tmp/datasets
Downloading https://ultralytics.com/assets/Arial.ttf to /root/.config/Ultralytics/Arial.ttf...
100% 755k/755k [00:00<00:00, 46.2MB/s]
Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5x.pt to yolov5x.pt...
100% 166M/166M [00:15<00:00, 10.9MB/s]
from n params module arguments
0 -1 1 8800 models.common.Conv [3, 80, 6, 2, 2]
1 -1 1 115520 models.common.Conv [80, 160, 3, 2]
2 -1 4 309120 models.common.C3 [160, 160, 4]
3 -1 1 461440 models.common.Conv [160, 320, 3, 2]
4 -1 8 2259200 models.common.C3 [320, 320, 8]
5 -1 1 1844480 models.common.Conv [320, 640, 3, 2]
6 -1 12 13125120 models.common.C3 [640, 640, 12]
7 -1 1 7375360 models.common.Conv [640, 1280, 3, 2]
8 -1 4 19676160 models.common.C3 [1280, 1280, 4]
9 -1 1 4099840 models.common.SPPF [1280, 1280, 5]
10 -1 1 820480 models.common.Conv [1280, 640, 1, 1]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
12 [-1, 6] 1 0 models.common.Concat [1]
13 -1 4 5332480 models.common.C3 [1280, 640, 4, False]
14 -1 1 205440 models.common.Conv [640, 320, 1, 1]
15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
16 [-1, 4] 1 0 models.common.Concat [1]
17 -1 4 1335040 models.common.C3 [640, 320, 4, False]
18 -1 1 922240 models.common.Conv [320, 320, 3, 2]
19 [-1, 14] 1 0 models.common.Concat [1]
20 -1 4 4922880 models.common.C3 [640, 640, 4, False]
21 -1 1 3687680 models.common.Conv [640, 640, 3, 2]
22 [-1, 10] 1 0 models.common.Concat [1]
23 -1 4 19676160 models.common.C3 [1280, 1280, 4, False]
24 [17, 20, 23] 1 571965 models.yolo.Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [320, 640, 1280]]
Model summary: 445 layers, 86749405 parameters, 86749405 gradients, 206.3 GFLOPs
Transferred 745/745 items from yolov5x.pt
AMP: checks passed ✅
optimizer: SGD(lr=0.01) with parameter groups 123 weight(decay=0.0), 126 weight(decay=0.0005), 126 bias
albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01), CLAHE(p=0.01, clip_limit=(1, 4.0), tile_grid_size=(8, 8))
train: Scanning /content/tmp/datasets/coco128/labels/train2017... 126 images, 2 backgrounds, 0 corrupt: 100% 128/128 [00:00<00:00, 1758.95it/s]
train: New cache created: /content/tmp/datasets/coco128/labels/train2017.cache
val: Scanning /content/tmp/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100% 128/128 [00:00<?, ?it/s]
AutoAnchor: 4.27 anchors/target, 0.994 Best Possible Recall (BPR). Current anchors are a good fit to dataset ✅
Plotting labels to runs/train/exp/labels.jpg...
Image sizes 640 train, 640 val
Using 2 dataloader workers
Logging results to runs/train/exp
Starting training for 300 epochs...
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
0/299 13.8G 0.03571 0.06081 0.01071 232 640: 100% 8/8 [00:13<00:00, 1.71s/it]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:04<00:00, 1.15s/it]
all 128 929 0.808 0.714 0.812 0.615
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
1/299 13.8G 0.03577 0.05759 0.01104 201 640: 100% 8/8 [00:08<00:00, 1.10s/it]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:03<00:00, 1.19it/s]
all 128 929 0.815 0.755 0.842 0.651
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
2/299 14.1G 0.03302 0.05204 0.009551 227 640: 100% 8/8 [00:08<00:00, 1.09s/it]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:03<00:00, 1.27it/s]
all 128 929 0.839 0.775 0.857 0.66
...(略)...
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
298/299 14.1G 0.01553 0.01716 0.002782 200 640: 100% 8/8 [00:08<00:00, 1.10s/it]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:03<00:00, 1.26it/s]
all 128 929 0.965 0.957 0.977 0.929
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
299/299 14.1G 0.01554 0.01778 0.002446 177 640: 100% 8/8 [00:08<00:00, 1.10s/it]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:03<00:00, 1.25it/s]
all 128 929 0.965 0.957 0.977 0.928
300 epochs completed in 1.291 hours.
Optimizer stripped from runs/train/exp/weights/last.pt, 174.1MB
Optimizer stripped from runs/train/exp/weights/best.pt, 174.1MB
Validating runs/train/exp/weights/best.pt...
Fusing layers...
Model summary: 322 layers, 86705005 parameters, 0 gradients, 205.5 GFLOPs
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:05<00:00, 1.46s/it]
all 128 929 0.965 0.957 0.977 0.931
person 128 254 1 0.979 0.995 0.944
bicycle 128 6 0.962 1 0.995 0.914
car 128 46 1 0.861 0.995 0.79
motorcycle 128 5 0.962 1 0.995 0.995
airplane 128 6 0.966 1 0.995 0.995
bus 128 7 0.97 1 0.995 0.941
train 128 3 0.945 1 0.995 0.995
truck 128 12 1 0.86 0.995 0.928
boat 128 6 0.965 1 0.995 0.924
traffic light 128 14 1 0.762 0.931 0.762
stop sign 128 2 0.928 1 0.995 0.995
bench 128 9 1 0.871 0.995 0.904
bird 128 16 0.989 1 0.995 0.969
cat 128 4 1 0.916 0.995 0.971
dog 128 9 0.979 1 0.995 0.995
horse 128 2 0.893 1 0.995 0.995
elephant 128 17 0.992 1 0.995 0.989
bear 128 1 0.885 1 0.995 0.995
zebra 128 4 0.954 1 0.995 0.995
giraffe 128 9 0.986 1 0.995 0.983
backpack 128 6 1 0.979 0.995 0.882
umbrella 128 18 0.991 1 0.995 0.966
handbag 128 19 1 0.945 0.995 0.871
tie 128 7 0.955 0.857 0.86 0.841
suitcase 128 4 0.956 1 0.995 0.995
frisbee 128 5 0.975 1 0.995 0.919
skis 128 1 0.889 1 0.995 0.995
snowboard 128 7 0.973 0.857 0.865 0.832
sports ball 128 6 0.978 0.833 0.845 0.755
kite 128 10 0.988 1 0.995 0.848
baseball bat 128 4 0.964 1 0.995 0.823
baseball glove 128 7 1 0.815 0.859 0.686
skateboard 128 5 0.968 1 0.995 0.995
tennis racket 128 7 0.959 0.857 0.86 0.844
bottle 128 18 0.995 0.944 0.992 0.886
wine glass 128 16 1 0.859 0.995 0.85
cup 128 36 0.966 1 0.995 0.949
fork 128 6 0.974 1 0.995 0.98
knife 128 16 1 0.854 0.988 0.829
spoon 128 22 0.987 1 0.995 0.906
bowl 128 28 1 0.883 0.925 0.866
banana 128 1 0.889 1 0.995 0.995
sandwich 128 2 0.778 1 0.995 0.995
orange 128 4 0.959 1 0.995 0.995
broccoli 128 11 0.984 1 0.995 0.961
carrot 128 24 0.982 1 0.995 0.953
hot dog 128 2 0.922 1 0.995 0.995
pizza 128 5 0.994 1 0.995 0.995
donut 128 14 0.985 1 0.995 0.995
cake 128 4 0.941 1 0.995 0.995
chair 128 35 1 0.931 0.995 0.94
couch 128 6 0.949 1 0.995 0.995
potted plant 128 14 0.986 1 0.995 0.995
bed 128 3 0.942 1 0.995 0.995
dining table 128 13 1 0.916 0.99 0.951
toilet 128 2 0.925 1 0.995 0.995
tv 128 2 0.924 1 0.995 0.995
laptop 128 3 0.91 0.667 0.671 0.671
mouse 128 2 0.94 1 0.995 0.946
remote 128 8 0.982 1 0.995 0.9
cell phone 128 8 0.98 1 0.995 0.91
microwave 128 3 0.947 1 0.995 0.995
oven 128 5 0.966 1 0.995 0.995
sink 128 6 1 0.798 0.995 0.892
refrigerator 128 5 0.963 1 0.995 0.995
book 128 29 1 0.709 0.889 0.762
clock 128 9 0.981 1 0.995 0.97
vase 128 2 0.927 1 0.995 0.945
scissors 128 1 0.924 1 0.995 0.895
teddy bear 128 21 0.991 1 0.995 0.995
toothbrush 128 5 0.942 1 0.995 0.995
Results saved to runs/train/exp%load_ext tensorboard %tensorboard --logdir runs
!python detect.py --source data/images --weights yolov5x.pt --conf 0.50
!python train.py --img 640 --batch 16 --epochs 30 --data coco128.yaml --weights yolov5s.pt
train: weights=yolov5s.pt, cfg=, data=coco128.yaml, hyp=data/hyps/hyp.scratch-low.yaml, epochs=30, batch_size=16, imgsz=640, 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, 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=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest
github: up to date with https://github.com/ultralytics/yolov5 ✅
YOLOv5 🚀 v7.0-66-g9650f16 Python-3.8.16 torch-1.13.0+cu116 CUDA:0 (Tesla T4, 15110MiB)
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/
Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to yolov5s.pt...
100% 14.1M/14.1M [00:00<00:00, 247MB/s]
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 295424 models.common.Conv [128, 256, 3, 2]
6 -1 3 625152 models.common.C3 [256, 256, 3]
7 -1 1 1180672 models.common.Conv [256, 512, 3, 2]
8 -1 1 1182720 models.common.C3 [512, 512, 1]
9 -1 1 656896 models.common.SPPF [512, 512, 5]
10 -1 1 131584 models.common.Conv [512, 256, 1, 1]
11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
12 [-1, 6] 1 0 models.common.Concat [1]
13 -1 1 361984 models.common.C3 [512, 256, 1, False]
14 -1 1 33024 models.common.Conv [256, 128, 1, 1]
15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
16 [-1, 4] 1 0 models.common.Concat [1]
17 -1 1 90880 models.common.C3 [256, 128, 1, False]
18 -1 1 147712 models.common.Conv [128, 128, 3, 2]
19 [-1, 14] 1 0 models.common.Concat [1]
20 -1 1 296448 models.common.C3 [256, 256, 1, False]
21 -1 1 590336 models.common.Conv [256, 256, 3, 2]
22 [-1, 10] 1 0 models.common.Concat [1]
23 -1 1 1182720 models.common.C3 [512, 512, 1, False]
24 [17, 20, 23] 1 229245 models.yolo.Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]
Model summary: 214 layers, 7235389 parameters, 7235389 gradients, 16.6 GFLOPs
Transferred 349/349 items from yolov5s.pt
AMP: checks passed ✅
optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 60 weight(decay=0.0005), 60 bias
albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01), CLAHE(p=0.01, clip_limit=(1, 4.0), tile_grid_size=(8, 8))
train: Scanning /content/tmp/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100% 128/128 [00:00<?, ?it/s]
val: Scanning /content/tmp/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100% 128/128 [00:00<?, ?it/s]
AutoAnchor: 4.27 anchors/target, 0.994 Best Possible Recall (BPR). Current anchors are a good fit to dataset ✅
Plotting labels to runs/train/exp2/labels.jpg...
Image sizes 640 train, 640 val
Using 2 dataloader workers
Logging results to runs/train/exp2
Starting training for 30 epochs...
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
0/29 3.74G 0.04619 0.07209 0.01703 232 640: 100% 8/8 [00:06<00:00, 1.29it/s]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:02<00:00, 1.34it/s]
all 128 929 0.675 0.598 0.681 0.45
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
1/29 5.36G 0.04618 0.06876 0.01807 201 640: 100% 8/8 [00:03<00:00, 2.59it/s]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:02<00:00, 1.50it/s]
all 128 929 0.711 0.633 0.715 0.478
...(略)...
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
28/29 5.36G 0.03609 0.04657 0.008075 231 640: 100% 8/8 [00:02<00:00, 2.77it/s]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:02<00:00, 1.42it/s]
all 128 929 0.891 0.836 0.897 0.658
Epoch GPU_mem box_loss obj_loss cls_loss Instances Size
29/29 5.36G 0.0366 0.04531 0.00704 199 640: 100% 8/8 [00:02<00:00, 2.90it/s]
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:02<00:00, 1.50it/s]
all 128 929 0.891 0.823 0.895 0.665
30 epochs completed in 0.053 hours.
Optimizer stripped from runs/train/exp2/weights/last.pt, 14.8MB
Optimizer stripped from runs/train/exp2/weights/best.pt, 14.8MB
Validating runs/train/exp2/weights/best.pt...
Fusing layers...
Model summary: 157 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs
Class Images Instances P R mAP50 mAP50-95: 100% 4/4 [00:04<00:00, 1.15s/it]
all 128 929 0.891 0.823 0.895 0.666
person 128 254 0.966 0.748 0.903 0.654
bicycle 128 6 0.952 0.833 0.837 0.637
car 128 46 0.957 0.565 0.697 0.326
motorcycle 128 5 0.936 1 0.995 0.876
airplane 128 6 0.926 1 0.995 0.876
bus 128 7 0.999 1 0.995 0.804
train 128 3 0.962 1 0.995 0.681
truck 128 12 0.861 0.519 0.864 0.541
boat 128 6 1 0.586 0.86 0.41
traffic light 128 14 1 0.388 0.528 0.32
stop sign 128 2 0.862 1 0.995 0.796
bench 128 9 0.957 0.889 0.975 0.661
bird 128 16 0.99 1 0.995 0.748
cat 128 4 1 0.966 0.995 0.847
dog 128 9 0.983 1 0.995 0.845
horse 128 2 0.875 1 0.995 0.821
elephant 128 17 0.983 0.941 0.95 0.807
bear 128 1 0.79 1 0.995 0.995
zebra 128 4 0.914 1 0.995 0.946
giraffe 128 9 0.986 1 0.995 0.801
backpack 128 6 0.769 0.833 0.837 0.541
umbrella 128 18 0.929 1 0.995 0.666
handbag 128 19 0.923 0.579 0.678 0.454
tie 128 7 1 0.849 0.858 0.661
suitcase 128 4 0.936 1 0.995 0.846
frisbee 128 5 0.91 0.8 0.8 0.601
skis 128 1 0.795 1 0.995 0.597
snowboard 128 7 0.967 0.857 0.875 0.681
sports ball 128 6 0.746 0.667 0.671 0.366
kite 128 10 0.844 0.544 0.796 0.368
baseball bat 128 4 0.772 0.5 0.685 0.423
baseball glove 128 7 0.779 0.429 0.627 0.367
skateboard 128 5 0.824 0.8 0.962 0.681
tennis racket 128 7 0.647 0.714 0.731 0.471
bottle 128 18 1 0.583 0.831 0.573
wine glass 128 16 0.706 0.751 0.89 0.517
cup 128 36 0.858 0.917 0.947 0.696
fork 128 6 0.972 0.833 0.863 0.623
knife 128 16 0.911 0.642 0.859 0.44
spoon 128 22 0.903 0.591 0.753 0.465
bowl 128 28 0.925 0.75 0.859 0.673
banana 128 1 0.858 1 0.995 0.796
sandwich 128 2 0.979 1 0.995 0.647
orange 128 4 0.913 1 0.995 0.679
broccoli 128 11 1 0.669 0.874 0.639
carrot 128 24 0.881 0.927 0.95 0.664
hot dog 128 2 0.813 1 0.995 0.995
pizza 128 5 1 0.894 0.995 0.79
donut 128 14 0.917 1 0.995 0.918
cake 128 4 0.88 1 0.995 0.92
chair 128 35 0.931 0.775 0.943 0.638
couch 128 6 0.837 0.833 0.972 0.786
potted plant 128 14 0.852 1 0.995 0.713
bed 128 3 0.911 1 0.995 0.864
dining table 128 13 0.968 0.692 0.902 0.66
toilet 128 2 0.86 1 0.995 0.846
tv 128 2 0.837 1 0.995 0.921
laptop 128 3 0.763 0.667 0.764 0.482
mouse 128 2 1 0.765 0.995 0.428
remote 128 8 1 0.729 0.804 0.563
cell phone 128 8 0.918 0.625 0.789 0.487
microwave 128 3 0.897 1 0.995 0.863
oven 128 5 0.909 0.8 0.866 0.635
sink 128 6 0.778 0.667 0.786 0.624
refrigerator 128 5 0.962 1 0.995 0.797
book 128 29 0.781 0.483 0.6 0.371
clock 128 9 1 0.971 0.995 0.836
vase 128 2 0.881 1 0.995 0.895
scissors 128 1 0 0 0.332 0.133
teddy bear 128 21 1 0.854 0.981 0.769
toothbrush 128 5 0.918 1 0.995 0.792
Results saved to runs/train/exp2