downlaod data from: https://universe.roboflow.com/roboflow-jvuqo/football-players-detection-3zvbc/dataset/2?ref=blog.roboflow.com

In [ ]:
!nvidia-smi
Sat Dec 23 23:54:13 2023       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.104.05             Driver Version: 535.104.05   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  Tesla T4                       Off | 00000000:00:04.0 Off |                    0 |
| N/A   43C    P8               9W /  70W |      0MiB / 15360MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
                                                                                         
+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|  No running processes found                                                           |
+---------------------------------------------------------------------------------------+

setup¶

In [ ]:
%pip install ultralytics
import ultralytics
ultralytics.checks()
Ultralytics YOLOv8.0.229 🚀 Python-3.10.12 torch-2.1.0+cu121 CUDA:0 (Tesla T4, 15102MiB)
Setup complete ✅ (2 CPUs, 12.7 GB RAM, 26.3/78.2 GB disk)
In [ ]:
from ultralytics import YOLO
import os
from IPython.display import display, Image
from IPython import display
display.clear_output()
!yolo mode=checks
Traceback (most recent call last):
  File "/usr/local/bin/yolo", line 8, in <module>
    sys.exit(entrypoint())
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/cfg/__init__.py", line 395, in entrypoint
    raise ValueError(f"Invalid 'mode={mode}'. Valid modes are {MODES}.\n{CLI_HELP_MSG}")
ValueError: Invalid 'mode=<module 'ultralytics.utils.checks' from '/usr/local/lib/python3.10/dist-packages/ultralytics/utils/checks.py'>'. Valid modes are ('train', 'val', 'predict', 'export', 'track', 'benchmark').

    Arguments received: ['yolo', 'mode=checks']. Ultralytics 'yolo' commands use the following syntax:

        yolo TASK MODE ARGS

        Where   TASK (optional) is one of ('detect', 'segment', 'classify', 'pose')
                MODE (required) is one of ('train', 'val', 'predict', 'export', 'track', 'benchmark')
                ARGS (optional) are any number of custom 'arg=value' pairs like 'imgsz=320' that override defaults.
                    See all ARGS at https://docs.ultralytics.com/usage/cfg or with 'yolo cfg'

    1. Train a detection model for 10 epochs with an initial learning_rate of 0.01
        yolo train data=coco128.yaml model=yolov8n.pt epochs=10 lr0=0.01

    2. Predict a YouTube video using a pretrained segmentation model at image size 320:
        yolo predict model=yolov8n-seg.pt source='https://youtu.be/LNwODJXcvt4' imgsz=320

    3. Val a pretrained detection model at batch-size 1 and image size 640:
        yolo val model=yolov8n.pt data=coco128.yaml batch=1 imgsz=640

    4. Export a YOLOv8n classification model to ONNX format at image size 224 by 128 (no TASK required)
        yolo export model=yolov8n-cls.pt format=onnx imgsz=224,128

    5. Run special commands:
        yolo help
        yolo checks
        yolo version
        yolo settings
        yolo copy-cfg
        yolo cfg

    Docs: https://docs.ultralytics.com
    Community: https://community.ultralytics.com
    GitHub: https://github.com/ultralytics/ultralytics
    

Train YOLOv8 on custom dataset¶

In [ ]:
!pip install roboflow

from roboflow import Roboflow
rf = Roboflow(api_key="8f60PiLN5qzO0Jq6glkd")
project = rf.workspace("nicolai-hoirup-nielsen").project("cup-detection-v2")
dataset = project.version(3).download("yolov8")
Collecting roboflow
  Downloading roboflow-1.1.14-py3-none-any.whl (68 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 69.0/69.0 kB 2.3 MB/s eta 0:00:00
Collecting certifi==2023.7.22 (from roboflow)
  Downloading certifi-2023.7.22-py3-none-any.whl (158 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 158.3/158.3 kB 6.8 MB/s eta 0:00:00
Collecting chardet==4.0.0 (from roboflow)
  Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 178.7/178.7 kB 9.1 MB/s eta 0:00:00
Collecting cycler==0.10.0 (from roboflow)
  Downloading cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)
Collecting idna==2.10 (from roboflow)
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.8/58.8 kB 8.4 MB/s eta 0:00:00
Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.10/dist-packages (from roboflow) (1.4.5)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from roboflow) (3.7.1)
Requirement already satisfied: numpy>=1.18.5 in /usr/local/lib/python3.10/dist-packages (from roboflow) (1.23.5)
Collecting opencv-python-headless==4.8.0.74 (from roboflow)
  Downloading opencv_python_headless-4.8.0.74-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (49.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.1/49.1 MB 18.6 MB/s eta 0:00:00
Requirement already satisfied: Pillow>=7.1.2 in /usr/local/lib/python3.10/dist-packages (from roboflow) (9.4.0)
Collecting pyparsing==2.4.7 (from roboflow)
  Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 67.8/67.8 kB 10.1 MB/s eta 0:00:00
Requirement already satisfied: python-dateutil in /usr/local/lib/python3.10/dist-packages (from roboflow) (2.8.2)
Collecting python-dotenv (from roboflow)
  Downloading python_dotenv-1.0.0-py3-none-any.whl (19 kB)
Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from roboflow) (2.31.0)
Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from roboflow) (1.16.0)
Collecting supervision (from roboflow)
  Downloading supervision-0.17.1-py3-none-any.whl (77 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 77.5/77.5 kB 12.1 MB/s eta 0:00:00
Requirement already satisfied: urllib3>=1.26.6 in /usr/local/lib/python3.10/dist-packages (from roboflow) (2.0.7)
Requirement already satisfied: tqdm>=4.41.0 in /usr/local/lib/python3.10/dist-packages (from roboflow) (4.66.1)
Requirement already satisfied: PyYAML>=5.3.1 in /usr/local/lib/python3.10/dist-packages (from roboflow) (6.0.1)
Collecting requests-toolbelt (from roboflow)
  Downloading requests_toolbelt-1.0.0-py2.py3-none-any.whl (54 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.5/54.5 kB 8.8 MB/s eta 0:00:00
Collecting python-magic (from roboflow)
  Downloading python_magic-0.4.27-py2.py3-none-any.whl (13 kB)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->roboflow) (1.2.0)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->roboflow) (4.46.0)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->roboflow) (23.2)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->roboflow) (3.3.2)
Requirement already satisfied: scipy>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from supervision->roboflow) (1.11.4)
Installing collected packages: python-magic, python-dotenv, pyparsing, opencv-python-headless, idna, cycler, chardet, certifi, supervision, requests-toolbelt, roboflow
  Attempting uninstall: pyparsing
    Found existing installation: pyparsing 3.1.1
    Uninstalling pyparsing-3.1.1:
      Successfully uninstalled pyparsing-3.1.1
  Attempting uninstall: opencv-python-headless
    Found existing installation: opencv-python-headless 4.8.1.78
    Uninstalling opencv-python-headless-4.8.1.78:
      Successfully uninstalled opencv-python-headless-4.8.1.78
  Attempting uninstall: idna
    Found existing installation: idna 3.6
    Uninstalling idna-3.6:
      Successfully uninstalled idna-3.6
  Attempting uninstall: cycler
    Found existing installation: cycler 0.12.1
    Uninstalling cycler-0.12.1:
      Successfully uninstalled cycler-0.12.1
  Attempting uninstall: chardet
    Found existing installation: chardet 5.2.0
    Uninstalling chardet-5.2.0:
      Successfully uninstalled chardet-5.2.0
  Attempting uninstall: certifi
    Found existing installation: certifi 2023.11.17
    Uninstalling certifi-2023.11.17:
      Successfully uninstalled certifi-2023.11.17
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
lida 0.0.10 requires fastapi, which is not installed.
lida 0.0.10 requires kaleido, which is not installed.
lida 0.0.10 requires python-multipart, which is not installed.
lida 0.0.10 requires uvicorn, which is not installed.
Successfully installed certifi-2023.7.22 chardet-4.0.0 cycler-0.10.0 idna-2.10 opencv-python-headless-4.8.0.74 pyparsing-2.4.7 python-dotenv-1.0.0 python-magic-0.4.27 requests-toolbelt-1.0.0 roboflow-1.1.14 supervision-0.17.1
loading Roboflow workspace...
loading Roboflow project...
Dependency ultralytics==8.0.196 is required but found version=8.0.229, to fix: `pip install ultralytics==8.0.196`
Downloading Dataset Version Zip in Cup-Detection-v2-3 to yolov8:: 100%|██████████| 10788/10788 [00:00<00:00, 66390.07it/s]

Extracting Dataset Version Zip to Cup-Detection-v2-3 in yolov8:: 100%|██████████| 730/730 [00:00<00:00, 8473.69it/s]
In [ ]:
!yolo task=detect mode=train model=yolov8m.pt data={dataset.location}/data.yaml epochs=25 imgsz=640
Downloading https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m.pt to 'yolov8m.pt'...
100% 49.7M/49.7M [00:00<00:00, 146MB/s]
Ultralytics YOLOv8.0.229 🚀 Python-3.10.12 torch-2.1.0+cu121 CUDA:0 (Tesla T4, 15102MiB)
engine/trainer: task=detect, mode=train, model=yolov8m.pt, data=/content/Cup-Detection-v2-3/data.yaml, epochs=25, time=None, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train, exist_ok=False, pretrained=True, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, 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, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, 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, pose=12.0, kobj=1.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, tracker=botsort.yaml, save_dir=runs/detect/train
Downloading https://ultralytics.com/assets/Arial.ttf to '/root/.config/Ultralytics/Arial.ttf'...
100% 755k/755k [00:00<00:00, 26.3MB/s]
2023-12-24 02:16:26.866507: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2023-12-24 02:16:26.866565: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2023-12-24 02:16:26.867892: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
Overriding model.yaml nc=80 with nc=6

                   from  n    params  module                                       arguments                     
  0                  -1  1      1392  ultralytics.nn.modules.conv.Conv             [3, 48, 3, 2]                 
  1                  -1  1     41664  ultralytics.nn.modules.conv.Conv             [48, 96, 3, 2]                
  2                  -1  2    111360  ultralytics.nn.modules.block.C2f             [96, 96, 2, True]             
  3                  -1  1    166272  ultralytics.nn.modules.conv.Conv             [96, 192, 3, 2]               
  4                  -1  4    813312  ultralytics.nn.modules.block.C2f             [192, 192, 4, True]           
  5                  -1  1    664320  ultralytics.nn.modules.conv.Conv             [192, 384, 3, 2]              
  6                  -1  4   3248640  ultralytics.nn.modules.block.C2f             [384, 384, 4, True]           
  7                  -1  1   1991808  ultralytics.nn.modules.conv.Conv             [384, 576, 3, 2]              
  8                  -1  2   3985920  ultralytics.nn.modules.block.C2f             [576, 576, 2, True]           
  9                  -1  1    831168  ultralytics.nn.modules.block.SPPF            [576, 576, 5]                 
 10                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']          
 11             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           
 12                  -1  2   1993728  ultralytics.nn.modules.block.C2f             [960, 384, 2]                 
 13                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']          
 14             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           
 15                  -1  2    517632  ultralytics.nn.modules.block.C2f             [576, 192, 2]                 
 16                  -1  1    332160  ultralytics.nn.modules.conv.Conv             [192, 192, 3, 2]              
 17            [-1, 12]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           
 18                  -1  2   1846272  ultralytics.nn.modules.block.C2f             [576, 384, 2]                 
 19                  -1  1   1327872  ultralytics.nn.modules.conv.Conv             [384, 384, 3, 2]              
 20             [-1, 9]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           
 21                  -1  2   4207104  ultralytics.nn.modules.block.C2f             [960, 576, 2]                 
 22        [15, 18, 21]  1   3779170  ultralytics.nn.modules.head.Detect           [6, [192, 384, 576]]          
Model summary: 295 layers, 25859794 parameters, 25859778 gradients, 79.1 GFLOPs

Transferred 469/475 items from pretrained weights
TensorBoard: Start with 'tensorboard --logdir runs/detect/train', view at http://localhost:6006/
Freezing layer 'model.22.dfl.conv.weight'
AMP: running Automatic Mixed Precision (AMP) checks with YOLOv8n...
Downloading https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt to 'yolov8n.pt'...
100% 6.23M/6.23M [00:00<00:00, 106MB/s]
WARNING ⚠️ NMS time limit 0.550s exceeded
AMP: checks passed ✅
train: Scanning /content/Cup-Detection-v2-3/train/labels... 330 images, 0 backgrounds, 0 corrupt: 100% 330/330 [00:00<00:00, 2153.17it/s]
train: New cache created: /content/Cup-Detection-v2-3/train/labels.cache
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))
val: Scanning /content/Cup-Detection-v2-3/valid/labels... 19 images, 0 backgrounds, 0 corrupt: 100% 19/19 [00:00<00:00, 1504.10it/s]
val: New cache created: /content/Cup-Detection-v2-3/valid/labels.cache
Plotting labels to runs/detect/train/labels.jpg... 
optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... 
optimizer: AdamW(lr=0.001, momentum=0.9) with parameter groups 77 weight(decay=0.0), 84 weight(decay=0.0005), 83 bias(decay=0.0)
25 epochs...

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       1/25      6.86G      1.695      2.859      1.902         69        640: 100% 21/21 [00:14<00:00,  1.42it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:01<00:00,  1.48s/it]
                   all         19         71      0.712       0.59      0.535      0.259

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       2/25      7.02G       1.33      1.497      1.542         83        640: 100% 21/21 [00:10<00:00,  2.01it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.00it/s]
                   all         19         71      0.602       0.71      0.614       0.34

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       3/25      7.05G       1.33      1.262      1.593         52        640: 100% 21/21 [00:10<00:00,  1.99it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.29it/s]
                   all         19         71      0.678      0.316      0.403      0.159

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       4/25      7.03G      1.316       1.14      1.569         93        640: 100% 21/21 [00:10<00:00,  1.99it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.26it/s]
                   all         19         71      0.322      0.668      0.405      0.221

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       5/25      7.05G      1.349      1.066       1.59         67        640: 100% 21/21 [00:10<00:00,  2.01it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  1.84it/s]
                   all         19         71      0.289      0.484      0.308      0.158

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       6/25      7.09G      1.283      1.017       1.58         57        640: 100% 21/21 [00:10<00:00,  2.07it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  1.69it/s]
                   all         19         71      0.537      0.516      0.518      0.268

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       7/25      7.08G      1.233     0.9163      1.506         54        640: 100% 21/21 [00:10<00:00,  2.05it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.16it/s]
                   all         19         71      0.616      0.652      0.712      0.395

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       8/25      7.08G      1.228     0.9206      1.513         67        640: 100% 21/21 [00:10<00:00,  1.95it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  2.38it/s]
                   all         19         71      0.795      0.553      0.688      0.397

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
       9/25      7.06G      1.194     0.8926      1.495         73        640: 100% 21/21 [00:11<00:00,  1.84it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  1.75it/s]
                   all         19         71      0.876      0.651      0.711      0.369

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      10/25      7.07G      1.147      0.822      1.452         67        640: 100% 21/21 [00:10<00:00,  1.97it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  2.09it/s]
                   all         19         71      0.911      0.794      0.799      0.523

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      11/25      7.04G      1.121     0.8286      1.442         51        640: 100% 21/21 [00:11<00:00,  1.90it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  2.86it/s]
                   all         19         71      0.938       0.78      0.804      0.408

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      12/25      7.09G      1.112     0.7667       1.44         81        640: 100% 21/21 [00:10<00:00,  1.93it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  1.97it/s]
                   all         19         71      0.929      0.732      0.802      0.531

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      13/25      7.05G      1.091     0.7576      1.435         74        640: 100% 21/21 [00:10<00:00,  1.99it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  2.19it/s]
                   all         19         71       0.91      0.705      0.781      0.406

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      14/25      7.07G      1.093     0.7322      1.428         53        640: 100% 21/21 [00:10<00:00,  2.01it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  1.97it/s]
                   all         19         71       0.92      0.754      0.806      0.479

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      15/25      7.07G       1.04     0.7014      1.345         76        640: 100% 21/21 [00:10<00:00,  1.96it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.32it/s]
                   all         19         71      0.971      0.811      0.823      0.482
Closing dataloader mosaic
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))

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      16/25      7.03G     0.9586     0.5895      1.373         35        640: 100% 21/21 [00:13<00:00,  1.58it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  2.89it/s]
                   all         19         71       0.91      0.784      0.816       0.55

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      17/25         7G     0.8901     0.5413      1.361         26        640: 100% 21/21 [00:10<00:00,  1.99it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  2.68it/s]
                   all         19         71      0.961      0.781      0.819      0.474

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      18/25      7.04G     0.9469     0.5527      1.409         36        640: 100% 21/21 [00:10<00:00,  1.97it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.28it/s]
                   all         19         71      0.939      0.798      0.807      0.402

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      19/25      7.04G      0.902     0.5102       1.36         36        640: 100% 21/21 [00:10<00:00,  1.94it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.44it/s]
                   all         19         71      0.954      0.823      0.815      0.533

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      20/25      7.05G     0.8322     0.4967      1.305         29        640: 100% 21/21 [00:10<00:00,  1.95it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.34it/s]
                   all         19         71      0.968      0.829      0.832      0.508

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      21/25      7.01G     0.7856     0.4515      1.266         36        640: 100% 21/21 [00:10<00:00,  1.96it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.41it/s]
                   all         19         71      0.979      0.816      0.821      0.551

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      22/25      7.02G     0.7648     0.4342      1.264         32        640: 100% 21/21 [00:10<00:00,  1.95it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.19it/s]
                   all         19         71       0.98      0.797      0.818      0.536

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      23/25      7.03G     0.7326     0.4127      1.231         28        640: 100% 21/21 [00:11<00:00,  1.82it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.20it/s]
                   all         19         71       0.98      0.818      0.822      0.505

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      24/25      7.05G      0.718     0.3998      1.217         31        640: 100% 21/21 [00:10<00:00,  1.94it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.45it/s]
                   all         19         71      0.967        0.8      0.809      0.527

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
      25/25         7G     0.7035     0.3788      1.217         29        640: 100% 21/21 [00:10<00:00,  1.92it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  2.07it/s]
                   all         19         71      0.952      0.803      0.807      0.538

25 epochs completed in 0.095 hours.
Optimizer stripped from runs/detect/train/weights/last.pt, 52.0MB
Optimizer stripped from runs/detect/train/weights/best.pt, 52.0MB

Validating runs/detect/train/weights/best.pt...
Ultralytics YOLOv8.0.229 🚀 Python-3.10.12 torch-2.1.0+cu121 CUDA:0 (Tesla T4, 15102MiB)
Model summary (fused): 218 layers, 25843234 parameters, 0 gradients, 78.7 GFLOPs
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 1/1 [00:00<00:00,  3.14it/s]
                   all         19         71      0.979      0.816      0.821      0.551
             Cocio Cup         19         16      0.982          1      0.995      0.742
                   Cup         19         11          1      0.895      0.976      0.537
         Halloween cup         19         14      0.917          1      0.967      0.581
      Hand painted cup         19         15      0.993          1      0.995      0.738
             White Cup         19         14      0.985          1      0.995      0.706
                   cup         19          1          1          0          0          0
Speed: 0.3ms preprocess, 10.7ms inference, 0.0ms loss, 1.0ms postprocess per image
Results saved to runs/detect/train
💡 Learn more at https://docs.ultralytics.com/modes/train
In [ ]:
Image(filename=f'/content/runs/detect/train/confusion_matrix.png', width=900)
Out[ ]:
In [ ]:
Image(filename=f'/content/runs/detect/train/results.png', width=800)
Out[ ]:
In [ ]:
!yolo task=detect mode=val model=/content/runs/detect/train/weights/best.pt data={dataset.location}/data.yaml
Ultralytics YOLOv8.0.229 🚀 Python-3.10.12 torch-2.1.0+cu121 CUDA:0 (Tesla T4, 15102MiB)
Model summary (fused): 218 layers, 25843234 parameters, 0 gradients, 78.7 GFLOPs
val: Scanning /content/Cup-Detection-v2-3/valid/labels.cache... 19 images, 0 backgrounds, 0 corrupt: 100% 19/19 [00:00<?, ?it/s]
                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100% 2/2 [00:01<00:00,  1.16it/s]
                   all         19         71      0.979      0.816      0.821      0.552
             Cocio Cup         19         16      0.981          1      0.995      0.743
                   Cup         19         11          1      0.896      0.976      0.553
         Halloween cup         19         14      0.916          1      0.967      0.576
      Hand painted cup         19         15      0.993          1      0.995      0.738
             White Cup         19         14      0.984          1      0.995      0.703
                   cup         19          1          1          0          0          0
Speed: 0.2ms preprocess, 40.3ms inference, 0.0ms loss, 30.1ms postprocess per image
Results saved to runs/detect/val3
💡 Learn more at https://docs.ultralytics.com/modes/val
In [ ]:
!yolo task=detect mode=predict model=/content/runs/detect/train/weights/best.pt conf=0.25 source={dataset.location}/test/images
Ultralytics YOLOv8.0.229 🚀 Python-3.10.12 torch-2.1.0+cu121 CUDA:0 (Tesla T4, 15102MiB)
Model summary (fused): 218 layers, 25843234 parameters, 0 gradients, 78.7 GFLOPs

image 1/10 /content/Cup-Detection-v2-3/test/images/img10_png.rf.1fd0fcc2f6a23a301d61081cc2d4073a.jpg: 640x640 1 Cocio Cup, 1 Cup, 1 Halloween cup, 1 Hand painted cup, 1 White Cup, 37.2ms
image 2/10 /content/Cup-Detection-v2-3/test/images/img1_png.rf.5daff3e408e1fd5975496a089b6d8229.jpg: 640x640 1 Cocio Cup, 1 Cup, 1 Halloween cup, 1 Hand painted cup, 1 White Cup, 37.1ms
image 3/10 /content/Cup-Detection-v2-3/test/images/img34_png.rf.bda5b0247fd2b04401cd4bf31084c623.jpg: 640x640 1 Cup, 1 Halloween cup, 1 Hand painted cup, 1 White Cup, 37.1ms
image 4/10 /content/Cup-Detection-v2-3/test/images/img43_png.rf.7760ddd4d75dc1bdda41cefd09cd3ffb.jpg: 640x640 1 Cocio Cup, 1 Cup, 1 Halloween cup, 1 Hand painted cup, 1 White Cup, 37.1ms
image 5/10 /content/Cup-Detection-v2-3/test/images/img59_png.rf.5fd0f9c99e67da7dc735600e9f07b33b.jpg: 640x640 1 Cocio Cup, 1 Halloween cup, 1 Hand painted cup, 1 White Cup, 30.8ms
image 6/10 /content/Cup-Detection-v2-3/test/images/img63_png.rf.67176af0b660c93f923f2d6c79fdf77c.jpg: 640x640 2 Halloween cups, 1 Hand painted cup, 1 White Cup, 1 cup, 24.8ms
image 7/10 /content/Cup-Detection-v2-3/test/images/img87_png.rf.b5c2f3e331144f024d7a64e26d5ca6b6.jpg: 640x640 1 White Cup, 24.8ms
image 8/10 /content/Cup-Detection-v2-3/test/images/img8_png.rf.4da077377f8f68f1f9a92ffd81d0aaf5.jpg: 640x640 1 Cocio Cup, 1 Cup, 1 Halloween cup, 1 Hand painted cup, 1 White Cup, 24.8ms
image 9/10 /content/Cup-Detection-v2-3/test/images/img90_png.rf.c3b09d58c4a52dd05f540e06f2a15bb1.jpg: 640x640 1 Cocio Cup, 1 cup, 24.8ms
image 10/10 /content/Cup-Detection-v2-3/test/images/img92_png.rf.6da9612f891b02a886793f9b6c7a1a94.jpg: 640x640 1 Cocio Cup, 19.8ms
Speed: 1.7ms preprocess, 29.8ms inference, 53.5ms postprocess per image at shape (1, 3, 640, 640)
Results saved to runs/detect/predict4
💡 Learn more at https://docs.ultralytics.com/modes/predict
In [ ]:
import glob
from IPython.display import Image, display

for image_path in glob.glob(f'/content/runs/detect/predict4/*.jpg')[:3]:
  display(Image(filename=image_path,height=600))
  print("\n")