Train Your OpenVINO™ Model Using YoloV8 Trainer For Any Dataset Format#
Prerequisite#
Download Six-sided Dice dataset#
This is a download link for Six-sided Dice dataset in Kaggle. Please download using this link and extract to your workspace directory. Then, you will have a d6-dice
directory with annotations and images in YOLO format as follows.
d6-dice
├── Annotations
│ ├── classes.txt
│ ├── IMG_20191208_111228.txt
│ ├── IMG_20191208_111246.txt
│ ├── ...
└── Images
├── IMG_20191208_111228.jpg
├── IMG_20191208_111246.jpg
├── ...
However, for import compatibility, obj.names
file must be added to d6-dice/obj.names
filepath for import compatibility. This obj.names
file includes the label names of the dataset, e.g., [dice1, ..., dice6]
. Therefore, you can write it with the following simple code. Please see Yolo Loose format for more details.
[1]:
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
import os
root_dir = "d6-dice"
names = """
dice1
dice2
dice3
dice4
dice5
dice6
"""
fpath = os.path.join(root_dir, "obj.names")
with open(fpath, "w") as fp:
fp.write(names)
Import dataset#
Firstly, we import this dataset using Datumaro Python API. The Six-sided Dice dataset has no subset split so that Datumaro will create “default” subset for it.
[2]:
from datumaro import Dataset
dataset = Dataset.import_from("./d6-dice", format="yolo")
dataset
[2]:
Dataset
size=250
source_path=./d6-dice
media_type=<class 'datumaro.components.media.Image'>
annotated_items_count=250
annotations_count=1795
subsets
default: # of items=250, # of annotated items=250, # of annotations=1795, annotation types=['bbox']
infos
categories
label: ['dice1', 'dice2', 'dice3', 'dice4', 'dice5', 'dice6']
Split subsets and export dataset#
There is no subset split in the imported dataset. However, Ultralytics-YOLO trainer must require “train” and “val” subsets (“test” is optional). So, we will create “train”, “val”, and “test” splits from the imported dataset.
[3]:
splited_dataset = dataset.transform(
"random_split", splits=[("train", 0.5), ("val", 0.2), ("test", 0.3)]
)
splited_dataset
[3]:
Dataset
size=250
source_path=./d6-dice
media_type=<class 'datumaro.components.media.Image'>
annotated_items_count=250
annotations_count=1795
subsets
test: # of items=75, # of annotated items=75, # of annotations=517, annotation types=['bbox']
train: # of items=125, # of annotated items=125, # of annotations=951, annotation types=['bbox']
val: # of items=50, # of annotated items=50, # of annotations=327, annotation types=['bbox']
infos
categories
label: ['dice1', 'dice2', 'dice3', 'dice4', 'dice5', 'dice6']
Now, we export the splited subsets to “yolo_ultralytics” format with save_media=True
for Ultralytics-YOLO trainer. It is recommended to set save_media=True
. If this option is enabled, Datumaro automatically copy-and-pastes the source images according to the correct directory structure of the target dataset format.
[4]:
splited_dataset.export("d6-dice-ultralytics", "yolo_ultralytics", save_media=True)
Train model with Ultralytics YOLOv8 trainer#
At first, we will install Ultralytics YOLOv8 trainer to train the model and export it to OpenVINO™ Intermediate Representation (IR). For export OpenVINO™ IR, we should install it with export
extra (ultralytics[export]
).
[ ]:
%pip install ultralytics[export]
[2]:
import os.path as osp
# To give the Ultralytics YOLO trainer an arbitrary dataset path,
# you must provide its absolute path.
data_fpath = osp.abspath(osp.join("d6-dice-ultralytics", "data.yaml"))
model_fpath = osp.abspath(osp.join("d6-dice-project", "train", "weights", "best.pt"))
Train yolov8n model#
We will train a yolov8n
model on the Six-sided Dataset for 100 epochs.
[7]:
!yolo detect train model=yolov8n.pt data={data_fpath} epochs=100 imgsz=640 project=d6-dice-project
Ultralytics YOLOv8.0.53 🚀 Python-3.9.13 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3090, 24268MiB)
yolo/engine/trainer: task=detect, mode=train, model=yolov8n.pt, data=/home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/data.yaml, epochs=100, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=d6-dice-project, name=None, exist_ok=False, pretrained=False, optimizer=SGD, verbose=True, seed=0, deterministic=True, single_cls=False, image_weights=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, hide_labels=False, hide_conf=False, vid_stride=1, line_thickness=3, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, boxes=True, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, 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=7.5, cls=0.5, dfl=1.5, fl_gamma=0.0, label_smoothing=0.0, nbs=64, 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, cfg=None, v5loader=False, tracker=botsort.yaml, save_dir=d6-dice-project/train2
Overriding model.yaml nc=80 with nc=6
from n params module arguments
0 -1 1 464 ultralytics.nn.modules.Conv [3, 16, 3, 2]
1 -1 1 4672 ultralytics.nn.modules.Conv [16, 32, 3, 2]
2 -1 1 7360 ultralytics.nn.modules.C2f [32, 32, 1, True]
3 -1 1 18560 ultralytics.nn.modules.Conv [32, 64, 3, 2]
4 -1 2 49664 ultralytics.nn.modules.C2f [64, 64, 2, True]
5 -1 1 73984 ultralytics.nn.modules.Conv [64, 128, 3, 2]
6 -1 2 197632 ultralytics.nn.modules.C2f [128, 128, 2, True]
7 -1 1 295424 ultralytics.nn.modules.Conv [128, 256, 3, 2]
8 -1 1 460288 ultralytics.nn.modules.C2f [256, 256, 1, True]
9 -1 1 164608 ultralytics.nn.modules.SPPF [256, 256, 5]
10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
11 [-1, 6] 1 0 ultralytics.nn.modules.Concat [1]
12 -1 1 148224 ultralytics.nn.modules.C2f [384, 128, 1]
13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest']
14 [-1, 4] 1 0 ultralytics.nn.modules.Concat [1]
15 -1 1 37248 ultralytics.nn.modules.C2f [192, 64, 1]
16 -1 1 36992 ultralytics.nn.modules.Conv [64, 64, 3, 2]
17 [-1, 12] 1 0 ultralytics.nn.modules.Concat [1]
18 -1 1 123648 ultralytics.nn.modules.C2f [192, 128, 1]
19 -1 1 147712 ultralytics.nn.modules.Conv [128, 128, 3, 2]
20 [-1, 9] 1 0 ultralytics.nn.modules.Concat [1]
21 -1 1 493056 ultralytics.nn.modules.C2f [384, 256, 1]
22 [15, 18, 21] 1 752482 ultralytics.nn.modules.Detect [6, [64, 128, 256]]
Model summary: 225 layers, 3012018 parameters, 3012002 gradients, 8.2 GFLOPs
Transferred 319/355 items from pretrained weights
AMP: running Automatic Mixed Precision (AMP) checks with YOLOv8n...
AMP: checks passed ✅
optimizer: SGD(lr=0.01) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias
train: Scanning /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/tra
train: New cache created: /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/train.cache
val: Scanning /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/val..
val: New cache created: /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/val.cache
Plotting labels to d6-dice-project/train2/labels.jpg...
Image sizes 640 train, 640 val
Using 8 dataloader workers
Logging results to d6-dice-project/train2
Starting training for 100 epochs...
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
1/100 2.14G 1.615 4.381 1.119 112 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0 0 0 0
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
2/100 2.14G 1.364 4.068 1.016 118 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.00656 0.248 0.0101 0.00435
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
3/100 2.14G 1.417 3.31 1.049 122 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.00288 0.134 0.00556 0.00287
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
4/100 2.14G 1.36 2.637 1.051 126 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.0162 0.648 0.0893 0.043
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
5/100 2.14G 1.36 2.334 1.052 162 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.015 0.616 0.111 0.0529
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
6/100 2.14G 1.427 2.235 1.063 187 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.0211 0.91 0.204 0.0995
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
7/100 2.14G 1.389 2.19 1.05 198 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.0228 0.968 0.236 0.137
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
8/100 2.14G 1.375 2.102 1.106 129 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.0225 0.98 0.241 0.117
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
9/100 2.14G 1.398 2.084 1.06 139 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.0231 1 0.274 0.163
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
10/100 2.14G 1.419 2.062 1.072 109 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.0233 1 0.288 0.176
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
11/100 2.14G 1.343 2.225 1.068 157 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.0229 0.985 0.289 0.126
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
12/100 2.14G 1.431 2.125 1.08 168 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.0243 0.986 0.272 0.125
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
13/100 2.14G 1.404 2.004 1.062 158 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.213 0.8 0.321 0.167
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
14/100 2.14G 1.365 1.995 1.064 177 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.343 0.369 0.368 0.207
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
15/100 2.14G 1.402 1.948 1.07 106 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.339 0.682 0.395 0.223
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
16/100 2.14G 1.387 1.906 1.06 139 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.275 0.559 0.368 0.211
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
17/100 2.26G 1.34 1.897 1.064 129 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.347 0.568 0.421 0.251
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
18/100 2.26G 1.292 1.918 1.042 188 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.617 0.303 0.379 0.23
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
19/100 2.26G 1.273 1.954 1.023 164 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.275 0.754 0.343 0.183
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
20/100 2.26G 1.358 1.803 1.026 133 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.301 0.839 0.437 0.221
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
21/100 2.26G 1.322 1.768 1.049 106 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.34 0.784 0.453 0.241
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
22/100 2.26G 1.293 1.775 1.056 131 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.262 0.644 0.402 0.25
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
23/100 2.26G 1.236 1.839 1.023 113 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.27 0.743 0.411 0.256
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
24/100 2.26G 1.348 1.758 1.01 223 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.343 0.885 0.519 0.332
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
25/100 2.26G 1.23 1.811 1.022 169 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.338 0.836 0.507 0.319
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
26/100 2.26G 1.188 1.745 1.013 119 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.418 0.76 0.531 0.346
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
27/100 2.26G 1.191 1.786 1.019 114 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.305 0.82 0.44 0.25
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
28/100 2.26G 1.207 1.639 1.009 134 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.418 0.866 0.567 0.34
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
29/100 2.26G 1.289 1.699 1.044 140 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.371 0.81 0.478 0.264
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
30/100 2.26G 1.297 1.612 1.019 119 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.494 0.772 0.605 0.303
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
31/100 2.26G 1.256 1.598 1.009 123 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.381 0.7 0.488 0.277
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
32/100 2.26G 1.213 1.655 1.016 125 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.346 0.772 0.499 0.279
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
33/100 2.26G 1.231 1.559 1.019 195 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.5 0.815 0.638 0.341
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
34/100 2.26G 1.233 1.536 1.032 134 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.482 0.798 0.671 0.414
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
35/100 2.26G 1.144 1.546 0.9998 125 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.309 0.642 0.419 0.249
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
36/100 2.26G 1.213 1.579 1.004 114 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.438 0.756 0.564 0.356
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
37/100 2.26G 1.21 1.533 1.008 128 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.501 0.75 0.629 0.377
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
38/100 2.26G 1.238 1.469 1.037 168 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.348 0.621 0.44 0.279
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
39/100 2.26G 1.22 1.492 1.042 105 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.575 0.73 0.665 0.422
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
40/100 2.26G 1.243 1.425 1.016 113 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.612 0.741 0.691 0.447
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
41/100 2.26G 1.229 1.482 1.026 76 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.639 0.821 0.751 0.482
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
42/100 2.26G 1.142 1.438 0.9861 122 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.626 0.787 0.756 0.476
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
43/100 2.26G 1.12 1.359 0.9938 125 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.61 0.79 0.74 0.476
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
44/100 2.26G 1.139 1.398 1.007 129 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.649 0.792 0.802 0.512
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
45/100 2.26G 1.137 1.294 0.9998 156 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.671 0.822 0.807 0.51
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
46/100 2.26G 1.138 1.291 1.031 152 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.539 0.697 0.673 0.429
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
47/100 2.26G 1.184 1.292 1.013 143 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.701 0.802 0.835 0.529
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
48/100 2.26G 1.213 1.261 1.034 148 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.7 0.847 0.834 0.541
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
49/100 2.26G 1.159 1.251 0.9938 144 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.727 0.852 0.83 0.495
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
50/100 2.26G 1.195 1.226 1.038 94 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.71 0.84 0.846 0.517
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
51/100 2.26G 1.127 1.236 0.9852 155 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.674 0.781 0.805 0.517
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
52/100 2.26G 1.174 1.236 1.029 132 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.687 0.777 0.831 0.544
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
53/100 2.26G 1.105 1.199 1.018 127 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.615 0.765 0.762 0.496
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
54/100 2.26G 1.119 1.191 0.981 169 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.619 0.834 0.822 0.534
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
55/100 2.26G 1.069 1.143 0.972 133 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.759 0.843 0.886 0.559
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
56/100 2.26G 1.134 1.117 0.9923 115 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.687 0.832 0.848 0.555
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
57/100 2.26G 1.128 1.16 0.9833 161 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.736 0.85 0.882 0.565
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
58/100 2.26G 1.109 1.129 0.9741 151 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.804 0.805 0.884 0.578
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
59/100 2.4G 1.17 1.14 1.016 81 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.803 0.854 0.901 0.563
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
60/100 2.4G 1.133 1.1 1.014 170 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.803 0.858 0.904 0.547
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
61/100 2.4G 1.102 1.084 0.9943 144 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.807 0.852 0.913 0.578
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
62/100 2.4G 1.063 1.086 0.9789 108 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.842 0.851 0.899 0.563
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
63/100 2.4G 1.09 1.082 0.9843 121 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.841 0.866 0.927 0.57
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
64/100 2.4G 1.046 1.09 0.973 115 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.825 0.871 0.927 0.581
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
65/100 2.4G 1.098 1.056 0.961 227 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.781 0.887 0.913 0.581
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
66/100 2.4G 1.027 1.001 0.9675 137 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.845 0.859 0.917 0.546
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
67/100 2.4G 1.098 1.044 0.9798 153 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.895 0.839 0.932 0.577
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
68/100 2.4G 1.105 1.018 0.9884 186 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.812 0.874 0.91 0.575
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
69/100 2.4G 1.08 1.011 0.9878 133 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.837 0.818 0.896 0.566
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
70/100 2.4G 1.02 1.04 0.9831 76 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.824 0.905 0.937 0.593
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
71/100 2.4G 1.023 1.022 0.9531 147 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.807 0.89 0.935 0.587
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
72/100 2.4G 1.103 0.9996 1.025 78 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.875 0.845 0.921 0.577
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
73/100 2.4G 1.039 0.9157 0.975 74 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.835 0.868 0.934 0.578
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
74/100 2.4G 1.103 1.004 0.9866 153 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.886 0.866 0.944 0.59
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
75/100 2.4G 1.043 0.9381 0.9686 185 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.895 0.882 0.947 0.571
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
76/100 2.4G 1.035 0.9351 0.9714 110 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.813 0.922 0.944 0.591
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
77/100 2.4G 1.019 0.9196 0.9839 101 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.843 0.896 0.943 0.593
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
78/100 2.4G 1.059 0.9575 0.9794 95 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.88 0.882 0.949 0.559
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
79/100 2.4G 1.049 0.9213 0.972 117 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.9 0.895 0.944 0.604
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
80/100 2.4G 1.015 0.878 0.9548 158 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.902 0.901 0.955 0.592
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
81/100 2.4G 1.014 0.901 0.9594 117 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.917 0.872 0.949 0.605
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
82/100 2.4G 1.07 0.9242 1.001 193 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.896 0.92 0.957 0.58
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
83/100 2.4G 1.018 0.8704 0.9674 96 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.903 0.934 0.959 0.591
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
84/100 2.4G 1.003 0.859 0.9545 120 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.913 0.866 0.961 0.611
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
85/100 2.4G 1.061 0.8796 0.9544 195 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.894 0.905 0.959 0.609
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
86/100 2.4G 1.069 0.9033 0.9926 146 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.87 0.911 0.958 0.606
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
87/100 2.4G 1.02 0.8343 0.961 127 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.931 0.901 0.964 0.613
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
88/100 2.4G 1.026 0.8555 0.9712 126 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.918 0.924 0.965 0.61
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
89/100 2.4G 1.039 0.8231 0.9747 103 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.876 0.934 0.963 0.602
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
90/100 2.4G 0.9811 0.8461 0.9502 178 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.895 0.879 0.959 0.608
Closing dataloader mosaic
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
91/100 2.4G 0.9937 0.774 1.009 108 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.89 0.916 0.956 0.594
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
92/100 2.4G 0.996 0.773 1.009 104 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.896 0.944 0.956 0.605
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
93/100 2.4G 1.006 0.7829 1.015 103 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.898 0.92 0.957 0.595
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
94/100 2.4G 1.016 0.7947 1.019 115 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.893 0.934 0.958 0.601
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
95/100 2.4G 0.9838 0.7514 1.008 117 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.915 0.924 0.964 0.607
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
96/100 2.4G 0.983 0.7637 1 112 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.909 0.919 0.964 0.603
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
97/100 2.4G 0.9728 0.7337 1.007 94 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.914 0.919 0.964 0.601
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
98/100 2.4G 0.9786 0.7598 0.9967 73 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.901 0.93 0.963 0.607
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
99/100 2.4G 0.9658 0.7412 0.9884 88 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.925 0.918 0.963 0.601
Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size
100/100 2.4G 0.9697 0.7439 0.9898 96 640: 1
Class Images Instances Box(P R mAP50 m
all 50 327 0.904 0.934 0.964 0.584
100 epochs completed in 0.293 hours.
Optimizer stripped from d6-dice-project/train2/weights/last.pt, 6.2MB
Optimizer stripped from d6-dice-project/train2/weights/best.pt, 6.2MB
Validating d6-dice-project/train2/weights/best.pt...
Ultralytics YOLOv8.0.53 🚀 Python-3.9.13 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3090, 24268MiB)
Model summary (fused): 168 layers, 3006818 parameters, 0 gradients, 8.1 GFLOPs
Class Images Instances Box(P R mAP50 m
all 50 327 0.931 0.902 0.964 0.611
dice1 50 72 0.997 0.972 0.989 0.582
dice2 50 48 0.933 0.917 0.976 0.651
dice3 50 51 0.909 0.782 0.938 0.647
dice4 50 40 0.887 0.9 0.949 0.636
dice5 50 68 0.925 0.9 0.966 0.59
dice6 50 48 0.934 0.938 0.966 0.558
Speed: 0.8ms preprocess, 0.8ms inference, 0.0ms loss, 1.0ms postprocess per image
Results saved to d6-dice-project/train2
Evaluate on the test set#
Now, we have the trained model saved in model_fpath
. We can evaluate this model on the test dataset as follows.
[3]:
!yolo detect val model={model_fpath} data={data_fpath} split=test
Ultralytics YOLOv8.0.53 🚀 Python-3.9.13 torch-1.13.1+cu117 CUDA:0 (NVIDIA GeForce RTX 3090, 24268MiB)
Model summary (fused): 168 layers, 3006818 parameters, 0 gradients, 8.1 GFLOPs
val: Scanning /home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/labels/test.
Class Images Instances Box(P R mAP50 m
all 75 517 0.953 0.932 0.975 0.632
dice1 75 83 0.977 0.952 0.987 0.662
dice2 75 101 0.951 0.931 0.976 0.649
dice3 75 84 0.962 0.903 0.96 0.596
dice4 75 82 0.93 0.97 0.98 0.615
dice5 75 88 0.938 0.92 0.969 0.629
dice6 75 79 0.96 0.914 0.976 0.642
Speed: 1.5ms preprocess, 1.0ms inference, 0.0ms loss, 26.3ms postprocess per image
Results saved to /home/vinnamki/ultralytics/runs/detect/val4
Export the trained model to OpenVINO™ IR#
So far, we have been able to successfully train our YOLOv8
model by converting the dataset format using Datumaro and passing it to the Ultralytics YOLOv8 trainer CLI. The final step is exporting the trained model to OpenVINO™ IR to accelerate model inference on any Intel™ device.
[4]:
!yolo detect export model={model_fpath} format=openvino
Ultralytics YOLOv8.0.53 🚀 Python-3.9.13 torch-1.13.1+cu117 CPU
Model summary (fused): 168 layers, 3006818 parameters, 0 gradients, 8.1 GFLOPs
PyTorch: starting from /home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best.pt with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 10, 8400) (5.9 MB)
ONNX: starting export with onnx 1.13.1...
ONNX: export success ✅ 0.4s, saved as /home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best.onnx (11.7 MB)
OpenVINO: starting export with openvino 2022.3.0-9052-9752fafe8eb-releases/2022/3...
OpenVINO: export success ✅ 0.7s, saved as /home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best_openvino_model/ (11.8 MB)
Export complete (1.4s)
Results saved to /home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights
Predict: yolo predict task=detect model=/home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best_openvino_model imgsz=640
Validate: yolo val task=detect model=/home/vinnamki/datumaro/notebooks/d6-dice-project/train/weights/best_openvino_model imgsz=640 data=/home/vinnamki/datumaro/notebooks/d6-dice-ultralytics/data.yaml
Visualize: https://netron.app