0% found this document useful (0 votes)
41 views47 pages

Underwater Object Detection With YOLO v8

Uploaded by

Rani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views47 pages

Underwater Object Detection With YOLO v8

Uploaded by

Rani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

11/9/24, 2:29 PM __notebook__

Import Necessary Libraries

Introducing Ultralytics YOLOv8, the latest version of the acclaimed real-time object detection and image
segmentation model.

Install YOLOv8 via the ultralytics pip package for the latest stable release

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 1/47
11/9/24, 2:29 PM __notebook__

In [1]:
# Install the ultralytics package from PyPI
! pip install ultralytics
! pip install wandb

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 2/47
11/9/24, 2:29 PM __notebook__

Collecting ultralytics
Downloading ultralytics-8.0.171-py3-none-any.whl (614 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 614.2/614.2 kB 13.3 MB/s et
a 0:00:00
Requirement already satisfied: matplotlib>=3.2.2 in /opt/conda/lib/
python3.10/site-packages (from ultralytics) (3.7.2)
Requirement already satisfied: numpy>=1.22.2 in /opt/conda/lib/pyth
on3.10/site-packages (from ultralytics) (1.23.5)
Requirement already satisfied: opencv-python>=4.6.0 in /opt/conda/l
ib/python3.10/site-packages (from ultralytics) (4.8.0.76)
Requirement already satisfied: pillow>=7.1.2 in /opt/conda/lib/pyth
on3.10/site-packages (from ultralytics) (9.5.0)
Requirement already satisfied: pyyaml>=5.3.1 in /opt/conda/lib/pyth
on3.10/site-packages (from ultralytics) (6.0)
Requirement already satisfied: requests>=2.23.0 in /opt/conda/lib/p
ython3.10/site-packages (from ultralytics) (2.31.0)
Requirement already satisfied: scipy>=1.4.1 in /opt/conda/lib/pytho
n3.10/site-packages (from ultralytics) (1.11.2)
Requirement already satisfied: torch>=1.8.0 in /opt/conda/lib/pytho
n3.10/site-packages (from ultralytics) (2.0.0)
Requirement already satisfied: torchvision>=0.9.0 in /opt/conda/li
b/python3.10/site-packages (from ultralytics) (0.15.1)
Requirement already satisfied: tqdm>=4.64.0 in /opt/conda/lib/pytho
n3.10/site-packages (from ultralytics) (4.66.1)
Requirement already satisfied: pandas>=1.1.4 in /opt/conda/lib/pyth
on3.10/site-packages (from ultralytics) (2.0.2)
Requirement already satisfied: seaborn>=0.11.0 in /opt/conda/lib/py
thon3.10/site-packages (from ultralytics) (0.12.2)
Requirement already satisfied: psutil in /opt/conda/lib/python3.10/
site-packages (from ultralytics) (5.9.3)
Requirement already satisfied: py-cpuinfo in /opt/conda/lib/python
3.10/site-packages (from ultralytics) (9.0.0)
Requirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/p
ython3.10/site-packages (from matplotlib>=3.2.2->ultralytics) (1.1.
0)
Requirement already satisfied: cycler>=0.10 in /opt/conda/lib/pytho
n3.10/site-packages (from matplotlib>=3.2.2->ultralytics) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/
python3.10/site-packages (from matplotlib>=3.2.2->ultralytics) (4.4
0.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/
python3.10/site-packages (from matplotlib>=3.2.2->ultralytics) (1.
4.4)

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 3/47
11/9/24, 2:29 PM __notebook__

Requirement already satisfied: packaging>=20.0 in /opt/conda/lib/py


thon3.10/site-packages (from matplotlib>=3.2.2->ultralytics) (21.3)
Requirement already satisfied: pyparsing<3.1,>=2.3.1 in /opt/conda/
lib/python3.10/site-packages (from matplotlib>=3.2.2->ultralytics)
(3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in /opt/conda/l
ib/python3.10/site-packages (from matplotlib>=3.2.2->ultralytics)
(2.8.2)
Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/pytho
n3.10/site-packages (from pandas>=1.1.4->ultralytics) (2023.3)
Requirement already satisfied: tzdata>=2022.1 in /opt/conda/lib/pyt
hon3.10/site-packages (from pandas>=1.1.4->ultralytics) (2023.3)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/con
da/lib/python3.10/site-packages (from requests>=2.23.0->ultralytic
s) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/pytho
n3.10/site-packages (from requests>=2.23.0->ultralytics) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/li
b/python3.10/site-packages (from requests>=2.23.0->ultralytics) (1.
26.15)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/li
b/python3.10/site-packages (from requests>=2.23.0->ultralytics) (20
23.7.22)
Requirement already satisfied: filelock in /opt/conda/lib/python3.1
0/site-packages (from torch>=1.8.0->ultralytics) (3.12.2)
Requirement already satisfied: typing-extensions in /opt/conda/lib/
python3.10/site-packages (from torch>=1.8.0->ultralytics) (4.6.3)
Requirement already satisfied: sympy in /opt/conda/lib/python3.10/s
ite-packages (from torch>=1.8.0->ultralytics) (1.12)
Requirement already satisfied: networkx in /opt/conda/lib/python3.1
0/site-packages (from torch>=1.8.0->ultralytics) (3.1)
Requirement already satisfied: jinja2 in /opt/conda/lib/python3.10/
site-packages (from torch>=1.8.0->ultralytics) (3.1.2)
Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.1
0/site-packages (from python-dateutil>=2.7->matplotlib>=3.2.2->ultr
alytics) (1.16.0)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/lib/py
thon3.10/site-packages (from jinja2->torch>=1.8.0->ultralytics) (2.
1.3)
Requirement already satisfied: mpmath>=0.19 in /opt/conda/lib/pytho
n3.10/site-packages (from sympy->torch>=1.8.0->ultralytics) (1.3.0)
Installing collected packages: ultralytics
Successfully installed ultralytics-8.0.171
Requirement already satisfied: wandb in /opt/conda/lib/python3.10/s
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 4/47
11/9/24, 2:29 PM __notebook__

ite-packages (0.15.9)
Requirement already satisfied: Click!=8.0.0,>=7.1 in /opt/conda/li
b/python3.10/site-packages (from wandb) (8.1.7)
Requirement already satisfied: GitPython!=3.1.29,>=1.0.0 in /opt/co
nda/lib/python3.10/site-packages (from wandb) (3.1.31)
Requirement already satisfied: requests<3,>=2.0.0 in /opt/conda/li
b/python3.10/site-packages (from wandb) (2.31.0)
Requirement already satisfied: psutil>=5.0.0 in /opt/conda/lib/pyth
on3.10/site-packages (from wandb) (5.9.3)
Requirement already satisfied: sentry-sdk>=1.0.0 in /opt/conda/lib/
python3.10/site-packages (from wandb) (1.30.0)
Requirement already satisfied: docker-pycreds>=0.4.0 in /opt/conda/
lib/python3.10/site-packages (from wandb) (0.4.0)
Requirement already satisfied: PyYAML in /opt/conda/lib/python3.10/
site-packages (from wandb) (6.0)
Requirement already satisfied: pathtools in /opt/conda/lib/python3.
10/site-packages (from wandb) (0.1.2)
Requirement already satisfied: setproctitle in /opt/conda/lib/pytho
n3.10/site-packages (from wandb) (1.3.2)
Requirement already satisfied: setuptools in /opt/conda/lib/python
3.10/site-packages (from wandb) (68.0.0)
Requirement already satisfied: appdirs>=1.4.3 in /opt/conda/lib/pyt
hon3.10/site-packages (from wandb) (1.4.4)
Requirement already satisfied: protobuf!=4.21.0,<5,>=3.19.0 in /op
t/conda/lib/python3.10/site-packages (from wandb) (3.20.3)
Requirement already satisfied: six>=1.4.0 in /opt/conda/lib/python
3.10/site-packages (from docker-pycreds>=0.4.0->wandb) (1.16.0)
Requirement already satisfied: gitdb<5,>=4.0.1 in /opt/conda/lib/py
thon3.10/site-packages (from GitPython!=3.1.29,>=1.0.0->wandb) (4.
0.10)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/con
da/lib/python3.10/site-packages (from requests<3,>=2.0.0->wandb)
(3.1.0)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/pytho
n3.10/site-packages (from requests<3,>=2.0.0->wandb) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/li
b/python3.10/site-packages (from requests<3,>=2.0.0->wandb) (1.26.1
5)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/li
b/python3.10/site-packages (from requests<3,>=2.0.0->wandb) (2023.
7.22)
Requirement already satisfied: smmap<6,>=3.0.1 in /opt/conda/lib/py

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 5/47
11/9/24, 2:29 PM __notebook__

thon3.10/site-packages (from gitdb<5,>=4.0.1->GitPython!=3.1.29,>=


1.0.0->wandb) (5.0.0)

In [2]:
# Importing the required libraries
import os
import random
import pandas as pd
import wandb
from kaggle_secrets import UserSecretsClient

import cv2
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

import torch
from ultralytics import YOLO
%matplotlib inline

/opt/conda/lib/python3.10/site-packages/scipy/__init__.py:146: User
Warning: A NumPy version >=1.16.5 and <1.23.0 is required for this
version of SciPy (detected version 1.23.5
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxver
sion}"

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 6/47
11/9/24, 2:29 PM __notebook__

In [3]:
# Wandb login:
user_secrets = UserSecretsClient()
secret_value = user_secrets.get_secret("wandb_api_key")
wandb.login(key=secret_value)

wandb: W&B API key is configured. Use `wandb login --relogin` to fo


rce relogin
wandb: WARNING If you're specifying your api key in code, ensure th
is code is not shared publicly.
wandb: WARNING Consider setting the WANDB_API_KEY environment varia
ble, or running `wandb login` from the command line.
wandb: Appending key for api.wandb.ai to your netrc file: /root/.ne
trc

Out[3]:
True

Explore the Dataset

In [4]:
# Define the paths to the images and labels directories
train_images = '/kaggle/input/aquarium-data-cots/aquarium_pretrain/trai
n/images'
train_labels = '/kaggle/input/aquarium-data-cots/aquarium_pretrain/trai
n/labels'

val_images = '/kaggle/input/aquarium-data-cots/aquarium_pretrain/valid/
images'
val_labels = '/kaggle/input/aquarium-data-cots/aquarium_pretrain/valid/
labels'

test_images = '/kaggle/input/aquarium-data-cots/aquarium_pretrain/test/
images'
test_labels = '/kaggle/input/aquarium-data-cots/aquarium_pretrain/test/
labels'

# Define the path to the yaml data file


yaml_path = '/kaggle/input/aquarium-data-cots/aquarium_pretrain/data.ya
ml'

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 7/47
11/9/24, 2:29 PM __notebook__

In [5]:
# Define the labels
classes = ['fish', 'jellyfish', 'penguin', 'puffin', 'shark', 'starfis
h', 'stingray']
Idx2Label = {idx: label for idx, label in enumerate(classes)}
Label2Index = {label: idx for idx, label in Idx2Label.items()}
print('Index to Label Mapping:', Idx2Label)
print('Label to Index Mapping:', Label2Index)

Index to Label Mapping: {0: 'fish', 1: 'jellyfish', 2: 'penguin',


3: 'puffin', 4: 'shark', 5: 'starfish', 6: 'stingray'}
Label to Index Mapping: {'fish': 0, 'jellyfish': 1, 'penguin': 2,
'puffin': 3, 'shark': 4, 'starfish': 5, 'stingray': 6}

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 8/47
11/9/24, 2:29 PM __notebook__

Visualizing sample images with corresponding annotation bounding boxes

In [6]:

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 9/47
11/9/24, 2:29 PM __notebook__

def visualize_image_with_annotation_bboxes(image_dir, label_dir):


# Get list of all the image files in the directory
image_files = sorted(os.listdir(image_dir))

# Choose 10 random image files from the list


sample_image_files = random.sample(image_files, 12)

# Set up the plot


fig, axs = plt.subplots(4, 3, figsize=(15, 20))

# Loop over the random images and plot the bounding boxes
for i, image_file in enumerate(sample_image_files):
row = i // 3
col = i % 3

# Load the image


image_path = os.path.join(image_dir, image_file)
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Load the labels for this image


label_path = os.path.join(label_dir, image_file[:-4] + '.txt')
f = open(label_path, 'r')

# Loop over the labels and plot the bounding boxes


for label in f:
class_id, x_center, y_center, width, height = map(float, la
bel.split())
h, w, _ = image.shape
x_min = int((x_center - width/2) * w)
y_min = int((y_center - height/2) * h)
x_max = int((x_center + width/2) * w)
y_max = int((y_center + height/2) * h)
cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 25
5, 0), 2)
cv2.putText(image, Idx2Label[int(class_id)], (x_min, y_mi
n), cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, color=(255, 255, 255), thick
ness=2)

axs[row, col].imshow(image)
axs[row, col].axis('off')

plt.show()

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 10/47
11/9/24, 2:29 PM __notebook__

# Visualize 6 sample images with bounding boxes


visualize_image_with_annotation_bboxes(train_images, train_labels)

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 11/47
11/9/24, 2:29 PM __notebook__

In [7]:
# Read a image by path
image_path = os.path.join(train_images, os.listdir(train_images)[100])
image = cv2.imread(image_path)

# Get the size of the image


height, width, channels = image.shape
print('The image has dimensions {}x{} and {} channels'.format(height, w
idth, channels))

The image has dimensions 1024x768 and 3 channels

In [8]:
%%writefile /kaggle/working/data.yaml
# Path
train: /kaggle/input/aquarium-data-cots/aquarium_pretrain/train/images
val: /kaggle/input/aquarium-data-cots/aquarium_pretrain/valid/images
test: /kaggle/input/aquarium-data-cots/aquarium_pretrain/test/images

# Classes
nc: 7
names: ['fish', 'jellyfish', 'penguin', 'puffin', 'shark', 'starfish',
'stingray']

Writing /kaggle/working/data.yaml

Model Training

Train mode is used for training a YOLOv8 model on a custom dataset. In this mode, the model is trained using
the specified dataset and hyperparameters. The training process involves optimizing the model's parameters so
that it can accurately predict the classes and locations of objects in an image.

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 12/47
11/9/24, 2:29 PM __notebook__

In [9]:
# Load a pretrained nano model
model = YOLO('yolov8n.pt')

# free up GPU memory


torch.cuda.empty_cache()

# Training the model


results = model.train(
data='/kaggle/working/data.yaml',
epochs=100,
imgsz=(height, width, channels),
seed=42,
batch=16,
workers=4,
name='yolov8n_custom')

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 13/47
11/9/24, 2:29 PM __notebook__

Downloading https://github.com/ultralytics/assets/releases/downloa
d/v0.0.0/yolov8n.pt to 'yolov8n.pt'...
100%|██████████| 6.23M/6.23M [00:00<00:00, 73.1MB/s]
Ultralytics YOLOv8.0.171 🚀 Python-3.10.12 torch-2.0.0 CUDA:0 (Tesl
a P100-PCIE-16GB, 16281MiB)
engine/trainer: task=detect, mode=train, model=yolov8n.pt, data=/ka
ggle/working/data.yaml, epochs=100, patience=50, batch=16, imgsz=(1
024, 768, 3), save=True, save_period=-1, cache=False, device=None,
workers=4, project=None, name=yolov8n_custom, exist_ok=False, pretr
ained=True, optimizer=auto, verbose=True, seed=42, deterministic=Tr
ue, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, re
sume=False, amp=True, fraction=1.0, profile=False, freeze=None, ove
rlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, sav
e_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, h
alf=False, dnn=False, plots=True, source=None, show=False, save_txt
=False, save_conf=False, save_crop=False, show_labels=True, show_co
nf=True, vid_stride=1, stream_buffer=False, line_width=None, visual
ize=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, works
pace=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, transl
ate=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=botso
rt.yaml, save_dir=runs/detect/yolov8n_custom
Downloading https://ultralytics.com/assets/Arial.ttf to '/root/.con
fig/Ultralytics/Arial.ttf'...
100%|██████████| 755k/755k [00:00<00:00, 21.7MB/s]
Overriding model.yaml nc=80 with nc=7

from n params module


arguments
0 -1 1 464 ultralytics.nn.modules.conv.C
onv [3, 16, 3, 2]
1 -1 1 4672 ultralytics.nn.modules.conv.C
onv [16, 32, 3, 2]
2 -1 1 7360 ultralytics.nn.modules.block.
C2f [32, 32, 1, True]
3 -1 1 18560 ultralytics.nn.modules.conv.C
onv [32, 64, 3, 2]
4 -1 2 49664 ultralytics.nn.modules.block.

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 14/47
11/9/24, 2:29 PM __notebook__

C2f [64, 64, 2, True]


5 -1 1 73984 ultralytics.nn.modules.conv.C
onv [64, 128, 3, 2]
6 -1 2 197632 ultralytics.nn.modules.block.
C2f [128, 128, 2, True]
7 -1 1 295424 ultralytics.nn.modules.conv.C
onv [128, 256, 3, 2]
8 -1 1 460288 ultralytics.nn.modules.block.
C2f [256, 256, 1, True]
9 -1 1 164608 ultralytics.nn.modules.block.
SPPF [256, 256, 5]
10 -1 1 0 torch.nn.modules.upsampling.U
psample [None, 2, 'nearest']
11 [-1, 6] 1 0 ultralytics.nn.modules.conv.C
oncat [1]
12 -1 1 148224 ultralytics.nn.modules.block.
C2f [384, 128, 1]
13 -1 1 0 torch.nn.modules.upsampling.U
psample [None, 2, 'nearest']
14 [-1, 4] 1 0 ultralytics.nn.modules.conv.C
oncat [1]
15 -1 1 37248 ultralytics.nn.modules.block.
C2f [192, 64, 1]
16 -1 1 36992 ultralytics.nn.modules.conv.C
onv [64, 64, 3, 2]
17 [-1, 12] 1 0 ultralytics.nn.modules.conv.C
oncat [1]
18 -1 1 123648 ultralytics.nn.modules.block.
C2f [192, 128, 1]
19 -1 1 147712 ultralytics.nn.modules.conv.C
onv [128, 128, 3, 2]
20 [-1, 9] 1 0 ultralytics.nn.modules.conv.C
oncat [1]
21 -1 1 493056 ultralytics.nn.modules.block.
C2f [384, 256, 1]
22 [15, 18, 21] 1 752677 ultralytics.nn.modules.head.D
etect [7, [64, 128, 256]]
Model summary: 225 layers, 3012213 parameters, 3012197 gradients

Transferred 319/355 items from pretrained weights


TensorBoard: Start with 'tensorboard --logdir runs/detect/yolov8n_c
ustom', view at http://localhost:6006/
wandb: Currently logged in as: quydaunguyenhust (quydau). Use `wand
b login --relogin` to force relogin
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 15/47
11/9/24, 2:29 PM __notebook__

cat: /sys/module/amdgpu/initstate: No such file or directory


wandb: Tracking run with wandb version 0.15.9
wandb: Run data is saved locally in /kaggle/working/wandb/run-20230
906_145110-id654wax
wandb: Run `wandb offline` to turn off syncing.
wandb: Syncing run yolov8n_custom
wandb: ⭐️ View project at https://wandb.ai/quydau/YOLOv8
wandb: 🚀 View run at https://wandb.ai/quydau/YOLOv8/runs/id654wax
Freezing layer 'model.22.dfl.conv.weight'
AMP: running Automatic Mixed Precision (AMP) checks with YOLOv8n...
AMP: checks passed ✅
WARNING ⚠️ updating to 'imgsz=1024'. 'train' and 'val' imgsz must b
e an integer, while 'predict' and 'export' imgsz may be a [h, w] li
st or an integer, i.e. 'yolo export imgsz=640,480' or 'yolo export
imgsz=640'
train: Scanning /kaggle/input/aquarium-data-cots/aquarium_pretrain/
train/labels... 448 images, 1 backgrounds, 0 corrupt: 100%|█████████
█| 448/448 [00:04<00:00, 96.31it/s]
train: WARNING ⚠️ Cache directory /kaggle/input/aquarium-data-cots/
aquarium_pretrain/train is not writeable, cache not saved.
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 /kaggle/input/aquarium-data-cots/aquarium_pretrain/va
lid/labels... 127 images, 0 backgrounds, 0 corrupt: 100%|██████████|
127/127 [00:01<00:00, 80.62it/s]
val: WARNING ⚠️ Cache directory /kaggle/input/aquarium-data-cots/aq
uarium_pretrain/valid is not writeable, cache not saved.
Plotting labels to runs/detect/yolov8n_custom/labels.jpg...
optimizer: AdamW(lr=0.000909, momentum=0.9) with parameter groups 5
7 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias(decay=0.0)
Image sizes 1024 train, 1024 val
Using 2 dataloader workers
Logging results to runs/detect/yolov8n_custom
Starting training for 100 epochs...

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
1/100 6.2G 1.522 3.763 1.408 128
1024: 100%|██████████| 28/28 [00:24<00:00, 1.14it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:04<00:00, 1.09s/it]
all 127 909 0.019 0.643
0.103 0.0537
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 16/47
11/9/24, 2:29 PM __notebook__

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
2/100 5.7G 1.52 2.786 1.339 166
1024: 100%|██████████| 28/28 [00:19<00:00, 1.44it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.18it/s]
all 127 909 0.575 0.146
0.195 0.111

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
3/100 5.99G 1.497 2.425 1.36 204
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.15it/s]
all 127 909 0.321 0.362
0.303 0.17

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
4/100 5.69G 1.52 2.244 1.334 204
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:04<00:00, 1.02s/it]
all 127 909 0.317 0.391
0.34 0.19

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
5/100 6.23G 1.486 2.035 1.326 202
1024: 100%|██████████| 28/28 [00:19<00:00, 1.45it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.25it/s]
all 127 909 0.419 0.394
0.376 0.199

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
6/100 5.81G 1.443 2.049 1.333 180
1024: 100%|██████████| 28/28 [00:19<00:00, 1.45it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.22it/s]
all 127 909 0.454 0.378
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 17/47
11/9/24, 2:29 PM __notebook__

0.367 0.184

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
7/100 5.95G 1.442 1.924 1.31 159
1024: 100%|██████████| 28/28 [00:19<00:00, 1.44it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.16it/s]
all 127 909 0.511 0.431
0.44 0.241

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
8/100 6.36G 1.427 1.741 1.262 126
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.28it/s]
all 127 909 0.556 0.472
0.509 0.288

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
9/100 5.71G 1.398 1.662 1.268 185
1024: 100%|██████████| 28/28 [00:18<00:00, 1.49it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.09it/s]
all 127 909 0.603 0.447
0.493 0.274

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
10/100 6.14G 1.368 1.624 1.256 263
1024: 100%|██████████| 28/28 [00:18<00:00, 1.50it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.30it/s]
all 127 909 0.578 0.464
0.48 0.271

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
11/100 6.2G 1.4 1.647 1.278 219
1024: 100%|██████████| 28/28 [00:19<00:00, 1.43it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.29it/s]
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 18/47
11/9/24, 2:29 PM __notebook__

all 127 909 0.623 0.542


0.558 0.31

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
12/100 6.21G 1.385 1.552 1.256 179
1024: 100%|██████████| 28/28 [00:19<00:00, 1.43it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.38it/s]
all 127 909 0.649 0.543
0.597 0.346

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
13/100 5.96G 1.349 1.501 1.235 178
1024: 100%|██████████| 28/28 [00:18<00:00, 1.48it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.11it/s]
all 127 909 0.661 0.575
0.614 0.361

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
14/100 6.08G 1.377 1.448 1.241 180
1024: 100%|██████████| 28/28 [00:19<00:00, 1.45it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.47it/s]
all 127 909 0.643 0.531
0.585 0.334

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
15/100 5.89G 1.347 1.453 1.245 74
1024: 100%|██████████| 28/28 [00:19<00:00, 1.43it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.47it/s]
all 127 909 0.652 0.622
0.641 0.362

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
16/100 5.86G 1.298 1.378 1.224 163
1024: 100%|██████████| 28/28 [00:19<00:00, 1.47it/s]
Class Images Instances Box(P R
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 19/47
11/9/24, 2:29 PM __notebook__

mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.53it/s]


all 127 909 0.697 0.562
0.613 0.359

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
17/100 5.7G 1.322 1.347 1.21 182
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.54it/s]
all 127 909 0.703 0.554
0.626 0.363

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
18/100 5.53G 1.29 1.294 1.208 140
1024: 100%|██████████| 28/28 [00:18<00:00, 1.51it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.48it/s]
all 127 909 0.717 0.641
0.677 0.391

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
19/100 5.65G 1.287 1.267 1.215 178
1024: 100%|██████████| 28/28 [00:20<00:00, 1.38it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.52it/s]
all 127 909 0.675 0.6
0.648 0.381

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
20/100 5.86G 1.306 1.253 1.202 234
1024: 100%|██████████| 28/28 [00:19<00:00, 1.43it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.64it/s]
all 127 909 0.701 0.642
0.682 0.405

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
21/100 6G 1.274 1.198 1.2 186
1024: 100%|██████████| 28/28 [00:19<00:00, 1.40it/s]
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 20/47
11/9/24, 2:29 PM __notebook__

Class Images Instances Box(P R


mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.62it/s]
all 127 909 0.728 0.611
0.655 0.387

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
22/100 5.89G 1.269 1.221 1.187 288
1024: 100%|██████████| 28/28 [00:18<00:00, 1.49it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.69it/s]
all 127 909 0.706 0.591
0.639 0.383

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
23/100 5.51G 1.275 1.185 1.2 306
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.50it/s]
all 127 909 0.638 0.621
0.64 0.386

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
24/100 5.76G 1.263 1.155 1.183 196
1024: 100%|██████████| 28/28 [00:20<00:00, 1.39it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.57it/s]
all 127 909 0.781 0.573
0.666 0.393

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
25/100 5.85G 1.231 1.177 1.165 251
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.67it/s]
all 127 909 0.733 0.583
0.66 0.393

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
26/100 5.73G 1.246 1.095 1.171 165
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 21/47
11/9/24, 2:29 PM __notebook__

1024: 100%|██████████| 28/28 [00:19<00:00, 1.46it/s]


Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.70it/s]
all 127 909 0.72 0.642
0.674 0.411

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
27/100 6.38G 1.216 1.076 1.161 229
1024: 100%|██████████| 28/28 [00:19<00:00, 1.43it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.74it/s]
all 127 909 0.735 0.614
0.664 0.384

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
28/100 5.52G 1.222 1.085 1.164 170
1024: 100%|██████████| 28/28 [00:20<00:00, 1.39it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.65it/s]
all 127 909 0.736 0.626
0.676 0.399

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
29/100 5.8G 1.214 1.069 1.157 136
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.49it/s]
all 127 909 0.742 0.6
0.671 0.396

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
30/100 5.94G 1.194 1.025 1.148 168
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.22it/s]
all 127 909 0.714 0.674
0.698 0.414

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 22/47
11/9/24, 2:29 PM __notebook__

31/100 5.51G 1.242 1.058 1.177 277


1024: 100%|██████████| 28/28 [00:19<00:00, 1.45it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.67it/s]
all 127 909 0.736 0.64
0.692 0.398

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
32/100 6G 1.173 0.9701 1.128 310
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.57it/s]
all 127 909 0.756 0.639
0.708 0.406

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
33/100 5.79G 1.195 0.9975 1.145 192
1024: 100%|██████████| 28/28 [00:20<00:00, 1.39it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.67it/s]
all 127 909 0.708 0.654
0.693 0.41

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
34/100 5.97G 1.187 0.9732 1.142 220
1024: 100%|██████████| 28/28 [00:19<00:00, 1.46it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.58it/s]
all 127 909 0.765 0.632
0.694 0.425

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
35/100 5.83G 1.172 0.9512 1.122 190
1024: 100%|██████████| 28/28 [00:19<00:00, 1.47it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.63it/s]
all 127 909 0.7 0.648
0.691 0.417

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 23/47
11/9/24, 2:29 PM __notebook__

Size
36/100 5.49G 1.171 0.9437 1.143 216
1024: 100%|██████████| 28/28 [00:19<00:00, 1.46it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.59it/s]
all 127 909 0.744 0.648
0.695 0.429

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
37/100 5.89G 1.147 0.9384 1.147 151
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.63it/s]
all 127 909 0.75 0.675
0.713 0.433

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
38/100 6.01G 1.159 0.9099 1.121 236
1024: 100%|██████████| 28/28 [00:20<00:00, 1.36it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.74it/s]
all 127 909 0.753 0.652
0.719 0.406

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
39/100 5.51G 1.188 0.9516 1.132 133
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.64it/s]
all 127 909 0.746 0.642
0.699 0.426

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
40/100 6.16G 1.132 0.9004 1.121 181
1024: 100%|██████████| 28/28 [00:18<00:00, 1.48it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.65it/s]
all 127 909 0.753 0.655
0.72 0.424

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 24/47
11/9/24, 2:29 PM __notebook__

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
41/100 5.88G 1.141 0.899 1.12 214
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.54it/s]
all 127 909 0.749 0.674
0.734 0.436

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
42/100 5.83G 1.158 0.9218 1.148 205
1024: 100%|██████████| 28/28 [00:19<00:00, 1.40it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.59it/s]
all 127 909 0.761 0.637
0.705 0.424

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
43/100 5.55G 1.097 0.8937 1.106 204
1024: 100%|██████████| 28/28 [00:19<00:00, 1.47it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.22it/s]
all 127 909 0.737 0.648
0.701 0.42

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
44/100 5.56G 1.115 0.8503 1.105 217
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.74it/s]
all 127 909 0.748 0.661
0.718 0.432

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
45/100 5.46G 1.131 0.8805 1.121 181
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.65it/s]
all 127 909 0.752 0.712
0.726 0.443
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 25/47
11/9/24, 2:29 PM __notebook__

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
46/100 6.25G 1.115 0.8635 1.096 317
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.50it/s]
all 127 909 0.792 0.644
0.736 0.44

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
47/100 5.47G 1.108 0.8292 1.084 223
1024: 100%|██████████| 28/28 [00:19<00:00, 1.43it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.66it/s]
all 127 909 0.768 0.65
0.722 0.43

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
48/100 5.66G 1.087 0.8452 1.087 186
1024: 100%|██████████| 28/28 [00:18<00:00, 1.49it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.58it/s]
all 127 909 0.784 0.642
0.72 0.436

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
49/100 5.92G 1.062 0.8108 1.095 142
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.54it/s]
all 127 909 0.742 0.692
0.73 0.444

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
50/100 5.77G 1.098 0.8104 1.087 196
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.56it/s]
all 127 909 0.733 0.714
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 26/47
11/9/24, 2:29 PM __notebook__

0.718 0.429

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
51/100 5.59G 1.084 0.8097 1.075 335
1024: 100%|██████████| 28/28 [00:19<00:00, 1.45it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.64it/s]
all 127 909 0.757 0.688
0.726 0.446

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
52/100 5.74G 1.068 0.7794 1.088 227
1024: 100%|██████████| 28/28 [00:18<00:00, 1.48it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.66it/s]
all 127 909 0.733 0.654
0.696 0.426

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
53/100 5.48G 1.081 0.7795 1.088 184
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.69it/s]
all 127 909 0.79 0.633
0.723 0.437

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
54/100 5.95G 1.032 0.7737 1.067 154
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.61it/s]
all 127 909 0.766 0.69
0.717 0.427

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
55/100 5.43G 1.061 0.7853 1.091 131
1024: 100%|██████████| 28/28 [00:19<00:00, 1.44it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.60it/s]
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 27/47
11/9/24, 2:29 PM __notebook__

all 127 909 0.776 0.647


0.727 0.442

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
56/100 5.69G 1.03 0.7569 1.061 267
1024: 100%|██████████| 28/28 [00:19<00:00, 1.46it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.57it/s]
all 127 909 0.756 0.667
0.703 0.419

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
57/100 6.1G 1.038 0.7584 1.062 211
1024: 100%|██████████| 28/28 [00:19<00:00, 1.43it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.63it/s]
all 127 909 0.786 0.66
0.738 0.447

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
58/100 5.8G 1.033 0.7446 1.062 230
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.62it/s]
all 127 909 0.8 0.69
0.744 0.448

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
59/100 5.73G 1.048 0.7461 1.066 261
1024: 100%|██████████| 28/28 [00:20<00:00, 1.39it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.74it/s]
all 127 909 0.759 0.694
0.721 0.431

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
60/100 6G 1.051 0.7544 1.078 152
1024: 100%|██████████| 28/28 [00:18<00:00, 1.48it/s]
Class Images Instances Box(P R
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 28/47
11/9/24, 2:29 PM __notebook__

mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.40it/s]


all 127 909 0.764 0.686
0.727 0.437

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
61/100 5.59G 0.9869 0.7215 1.049 159
1024: 100%|██████████| 28/28 [00:19<00:00, 1.47it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.60it/s]
all 127 909 0.802 0.646
0.72 0.431

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
62/100 5.51G 1.009 0.7272 1.055 221
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.57it/s]
all 127 909 0.775 0.676
0.719 0.433

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
63/100 5.9G 1.034 0.7216 1.053 210
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.61it/s]
all 127 909 0.748 0.693
0.726 0.445

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
64/100 5.92G 0.9965 0.7152 1.041 141
1024: 100%|██████████| 28/28 [00:19<00:00, 1.46it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.33it/s]
all 127 909 0.759 0.682
0.726 0.443

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
65/100 5.45G 0.9934 0.699 1.049 169
1024: 100%|██████████| 28/28 [00:19<00:00, 1.46it/s]
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 29/47
11/9/24, 2:29 PM __notebook__

Class Images Instances Box(P R


mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.67it/s]
all 127 909 0.827 0.664
0.742 0.454

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
66/100 5.94G 0.9848 0.7046 1.036 215
1024: 100%|██████████| 28/28 [00:20<00:00, 1.37it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.69it/s]
all 127 909 0.76 0.645
0.708 0.423

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
67/100 5.77G 1.01 0.7029 1.061 155
1024: 100%|██████████| 28/28 [00:19<00:00, 1.44it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.45it/s]
all 127 909 0.77 0.677
0.715 0.445

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
68/100 5.71G 0.9844 0.6969 1.048 189
1024: 100%|██████████| 28/28 [00:19<00:00, 1.43it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.61it/s]
all 127 909 0.757 0.707
0.733 0.443

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
69/100 5.83G 0.9698 0.6832 1.047 214
1024: 100%|██████████| 28/28 [00:18<00:00, 1.48it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.54it/s]
all 127 909 0.765 0.706
0.745 0.454

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
70/100 5.53G 0.9866 0.6838 1.054 154
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 30/47
11/9/24, 2:29 PM __notebook__

1024: 100%|██████████| 28/28 [00:20<00:00, 1.39it/s]


Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.77it/s]
all 127 909 0.787 0.689
0.729 0.445

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
71/100 5.54G 0.9858 0.693 1.047 207
1024: 100%|██████████| 28/28 [00:20<00:00, 1.40it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.61it/s]
all 127 909 0.796 0.677
0.736 0.448

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
72/100 6.1G 0.9733 0.6739 1.031 199
1024: 100%|██████████| 28/28 [00:20<00:00, 1.39it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.81it/s]
all 127 909 0.738 0.711
0.739 0.44

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
73/100 5.74G 0.9483 0.6582 1.028 196
1024: 100%|██████████| 28/28 [00:19<00:00, 1.47it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.69it/s]
all 127 909 0.758 0.725
0.744 0.446

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
74/100 6.11G 0.9677 0.6681 1.035 266
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.79it/s]
all 127 909 0.794 0.677
0.737 0.446

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 31/47
11/9/24, 2:29 PM __notebook__

75/100 5.77G 0.9566 0.6589 1.03 163


1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.83it/s]
all 127 909 0.766 0.7
0.745 0.463

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
76/100 5.46G 0.9638 0.6717 1.03 208
1024: 100%|██████████| 28/28 [00:19<00:00, 1.42it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.63it/s]
all 127 909 0.755 0.721
0.728 0.449

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
77/100 5.3G 0.9366 0.6528 1.027 160
1024: 100%|██████████| 28/28 [00:19<00:00, 1.44it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.25it/s]
all 127 909 0.749 0.71
0.739 0.455

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
78/100 6.01G 0.922 0.6335 1.026 203
1024: 100%|██████████| 28/28 [00:19<00:00, 1.44it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.70it/s]
all 127 909 0.802 0.67
0.738 0.448

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
79/100 6.15G 0.9283 0.6467 1.021 175
1024: 100%|██████████| 28/28 [00:19<00:00, 1.44it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.65it/s]
all 127 909 0.788 0.684
0.748 0.458

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 32/47
11/9/24, 2:29 PM __notebook__

Size
80/100 5.68G 0.9149 0.6278 1.008 166
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.52it/s]
all 127 909 0.77 0.701
0.751 0.461

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
81/100 5.97G 0.9153 0.6207 1.012 229
1024: 100%|██████████| 28/28 [00:19<00:00, 1.45it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.36it/s]
all 127 909 0.803 0.684
0.749 0.463

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
82/100 5.88G 0.9373 0.6327 1.018 132
1024: 100%|██████████| 28/28 [00:19<00:00, 1.45it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.56it/s]
all 127 909 0.753 0.707
0.737 0.457

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
83/100 5.93G 0.9281 0.6306 1.018 201
1024: 100%|██████████| 28/28 [00:20<00:00, 1.40it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.74it/s]
all 127 909 0.767 0.68
0.733 0.451

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
84/100 5.9G 0.9289 0.6316 1.023 139
1024: 100%|██████████| 28/28 [00:20<00:00, 1.38it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.56it/s]
all 127 909 0.775 0.685
0.737 0.457

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 33/47
11/9/24, 2:29 PM __notebook__

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
85/100 6.12G 0.9055 0.6158 1.017 230
1024: 100%|██████████| 28/28 [00:18<00:00, 1.48it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.51it/s]
all 127 909 0.783 0.666
0.736 0.459

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
86/100 6G 0.9116 0.6125 1.007 240
1024: 100%|██████████| 28/28 [00:18<00:00, 1.48it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.67it/s]
all 127 909 0.773 0.69
0.741 0.46

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
87/100 5.85G 0.8999 0.6095 0.9994 199
1024: 100%|██████████| 28/28 [00:20<00:00, 1.37it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.56it/s]
all 127 909 0.779 0.698
0.748 0.466

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
88/100 6.33G 0.9173 0.6126 1.017 236
1024: 100%|██████████| 28/28 [00:20<00:00, 1.38it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.68it/s]
all 127 909 0.771 0.689
0.744 0.47

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
89/100 5.76G 0.8968 0.6033 1.017 157
1024: 100%|██████████| 28/28 [00:20<00:00, 1.40it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.55it/s]
all 127 909 0.8 0.665
0.745 0.464
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 34/47
11/9/24, 2:29 PM __notebook__

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
90/100 5.85G 0.8985 0.5989 1.005 154
1024: 100%|██████████| 28/28 [00:19<00:00, 1.41it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.68it/s]
all 127 909 0.735 0.735
0.747 0.46
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
91/100 5.47G 0.8997 0.6294 1 80
1024: 100%|██████████| 28/28 [00:21<00:00, 1.27it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.64it/s]
all 127 909 0.753 0.698
0.735 0.454

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
92/100 5.6G 0.8823 0.5868 0.9865 136
1024: 100%|██████████| 28/28 [00:19<00:00, 1.46it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.82it/s]
all 127 909 0.742 0.709
0.739 0.452

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
93/100 5.6G 0.841 0.553 0.9792 128
1024: 100%|██████████| 28/28 [00:17<00:00, 1.56it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.45it/s]
all 127 909 0.771 0.706
0.744 0.451

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
94/100 5.52G 0.8558 0.5498 0.9796 89
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 35/47
11/9/24, 2:29 PM __notebook__

1024: 100%|██████████| 28/28 [00:17<00:00, 1.61it/s]


Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.71it/s]
all 127 909 0.772 0.712
0.74 0.455

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
95/100 5.45G 0.8583 0.558 0.9855 160
1024: 100%|██████████| 28/28 [00:18<00:00, 1.52it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.63it/s]
all 127 909 0.774 0.717
0.747 0.455

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
96/100 5.49G 0.8471 0.5364 0.9698 96
1024: 100%|██████████| 28/28 [00:19<00:00, 1.46it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.70it/s]
all 127 909 0.776 0.699
0.74 0.451

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
97/100 5.45G 0.8391 0.5332 0.9726 126
1024: 100%|██████████| 28/28 [00:18<00:00, 1.53it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.63it/s]
all 127 909 0.78 0.712
0.738 0.45

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
98/100 5.3G 0.831 0.524 0.9716 119
1024: 100%|██████████| 28/28 [00:17<00:00, 1.59it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.66it/s]
all 127 909 0.745 0.732
0.737 0.454

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 36/47
11/9/24, 2:29 PM __notebook__

99/100 5.6G 0.8155 0.5354 0.9615 108


1024: 100%|██████████| 28/28 [00:18<00:00, 1.49it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.65it/s]
all 127 909 0.802 0.685
0.736 0.454

Epoch GPU_mem box_loss cls_loss dfl_loss Instances


Size
100/100 5.47G 0.8066 0.5115 0.9659 126
1024: 100%|██████████| 28/28 [00:18<00:00, 1.52it/s]
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:02<00:00, 1.51it/s]
all 127 909 0.783 0.697
0.738 0.454

100 epochs completed in 0.681 hours.


Optimizer stripped from runs/detect/yolov8n_custom/weights/last.pt,
6.3MB
Optimizer stripped from runs/detect/yolov8n_custom/weights/best.pt,
6.3MB

Validating runs/detect/yolov8n_custom/weights/best.pt...
Ultralytics YOLOv8.0.171 🚀 Python-3.10.12 torch-2.0.0 CUDA:0 (Tesl
a P100-PCIE-16GB, 16281MiB)
Model summary (fused): 168 layers, 3007013 parameters, 0 gradients
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:01<00:00, 3.04it/s]
all 127 909 0.772 0.689
0.743 0.47
fish 127 459 0.817 0.763
0.822 0.475
jellyfish 127 155 0.873 0.819
0.923 0.548
penguin 127 104 0.637 0.644
0.672 0.344
puffin 127 74 0.75 0.528
0.564 0.311
shark 127 57 0.737 0.64
0.663 0.47
starfish 127 27 0.84 0.704
0.797 0.579
stingray 127 33 0.75 0.727
0.761 0.562
https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 37/47
11/9/24, 2:29 PM __notebook__

Speed: 0.3ms preprocess, 3.9ms inference, 0.0ms loss, 1.3ms postpro


cess per image

Model Performance:

Train Box Loss: measures the difference between the predicted bounding boxes and the actual bounding
boxes of the objects in the training data.

Train Class Loss: measures the difference between the predicted class probabilities and the actual class
labels of the objects in the training data.

Train DFL (Dynamic Feature Learning) Loss: measures the difference between the predicted feature maps
and the actual feature maps of the objects in the training data.
Metrics Precision (B): measures the proportion of true positive detections among all the predicted
bounding boxes.

Metrics Recall (B): metric measures the proportion of true positive detections among all the actual
bounding boxes.

Metrics mAP50 (B): measures the mean average precision of the model across different object categories,
with a 50% intersection-over-union (IoU) threshold.

Metrics mAP50-95 (B): measures the mean average precision of the model across different object
categories, with IoU thresholds ranging from 50% to 95%.

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 38/47
11/9/24, 2:29 PM __notebook__

In [10]:

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 39/47
11/9/24, 2:29 PM __notebook__

%matplotlib inline
# read in the results.csv file as a pandas dataframe
df = pd.read_csv('/kaggle/working/runs/detect/yolov8n_custom/results.cs
v')
df.columns = df.columns.str.strip()

# create subplots using seaborn


fig, axs = plt.subplots(nrows=5, ncols=2, figsize=(15, 15))

# plot the columns using seaborn


sns.lineplot(x='epoch', y='train/box_loss', data=df, ax=axs[0,0])
sns.lineplot(x='epoch', y='train/cls_loss', data=df, ax=axs[0,1])
sns.lineplot(x='epoch', y='train/dfl_loss', data=df, ax=axs[1,0])
sns.lineplot(x='epoch', y='metrics/precision(B)', data=df, ax=axs[1,1])
sns.lineplot(x='epoch', y='metrics/recall(B)', data=df, ax=axs[2,0])
sns.lineplot(x='epoch', y='metrics/mAP50(B)', data=df, ax=axs[2,1])
sns.lineplot(x='epoch', y='metrics/mAP50-95(B)', data=df, ax=axs[3,0])
sns.lineplot(x='epoch', y='val/box_loss', data=df, ax=axs[3,1])
sns.lineplot(x='epoch', y='val/cls_loss', data=df, ax=axs[4,0])
sns.lineplot(x='epoch', y='val/dfl_loss', data=df, ax=axs[4,1])

# set titles and axis labels for each subplot


axs[0,0].set(title='Train Box Loss')
axs[0,1].set(title='Train Class Loss')
axs[1,0].set(title='Train DFL Loss')
axs[1,1].set(title='Metrics Precision (B)')
axs[2,0].set(title='Metrics Recall (B)')
axs[2,1].set(title='Metrics mAP50 (B)')
axs[3,0].set(title='Metrics mAP50-95 (B)')
axs[3,1].set(title='Validation Box Loss')
axs[4,0].set(title='Validation Class Loss')
axs[4,1].set(title='Validation DFL Loss')

# add suptitle and subheader


plt.suptitle('Training Metrics and Loss', fontsize=24)

# adjust top margin to make space for suptitle


plt.subplots_adjust(top=0.8)

# adjust spacing between subplots


plt.tight_layout()

plt.show()

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 40/47
11/9/24, 2:29 PM __notebook__

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 41/47
11/9/24, 2:29 PM __notebook__

Evaluation

In [11]:
# Loading the best performing model
model = YOLO('/kaggle/working/runs/detect/yolov8n_custom/weights/best.p
t')

# Evaluating the model on test dataset


metrics = model.val(conf=0.25, split='test')

Ultralytics YOLOv8.0.171 🚀 Python-3.10.12 torch-2.0.0 CUDA:0 (Tesl


a P100-PCIE-16GB, 16281MiB)
Model summary (fused): 168 layers, 3007013 parameters, 0 gradients
val: Scanning /kaggle/input/aquarium-data-cots/aquarium_pretrain/te
st/labels... 63 images, 0 backgrounds, 0 corrupt: 100%|██████████| 6
3/63 [00:00<00:00, 90.35it/s]
val: WARNING ⚠️ Cache directory /kaggle/input/aquarium-data-cots/aq
uarium_pretrain/test is not writeable, cache not saved.
Class Images Instances Box(P R
mAP50 mAP50-95): 100%|██████████| 4/4 [00:04<00:00, 1.09s/it]
all 63 584 0.816 0.683
0.796 0.533
fish 63 249 0.843 0.649
0.805 0.526
jellyfish 63 154 0.888 0.772
0.866 0.608
penguin 63 82 0.946 0.638
0.837 0.4
puffin 63 35 0.725 0.302
0.501 0.289
shark 63 38 0.743 0.737
0.832 0.603
starfish 63 11 0.746 0.818
0.831 0.646
stingray 63 15 0.819 0.867
0.897 0.656
Speed: 17.4ms preprocess, 12.2ms inference, 0.0ms loss, 1.7ms postp
rocess per image
Results saved to runs/detect/val

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 42/47
11/9/24, 2:29 PM __notebook__

In [12]:
print(f"Mean Average Precision @.5:.95 : {metrics.box.map}")
print(f"Mean Average Precision @ .50 : {metrics.box.map50}")
print(f"Mean Average Precision @ .70 : {metrics.box.map75}")

Mean Average Precision @.5:.95 : 0.5325153818291493


Mean Average Precision @ .50 : 0.7957134201168232
Mean Average Precision @ .70 : 0.606471093124351

Making Predictions on Test Images

In [13]:
# Function to perform detections with trained model
def predict_detection(image_path):
# Read the image
image = cv2.imread(image_path)

# Pass the image through the detection model and get the result
detect_result = model(image)

# Plot the detections


detect_image = detect_result[0].plot()

# Convert the image to RGB format


detect_image = cv2.cvtColor(detect_image, cv2.COLOR_BGR2RGB)

return detect_image

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 43/47
11/9/24, 2:29 PM __notebook__

In [14]:
# Get list of all the image files in the test directory
image_files = sorted(os.listdir(test_images))

# Choose 12 random image files from the list


sample_image_files = random.sample(image_files, 12)

# Set up the plot


fig, axs = plt.subplots(4, 3, figsize=(15, 20))

# Loop over the random images and plot the detections of the trained mod
el
for i, image_file in enumerate(sample_image_files):
row = i // 3
col = i % 3

# Load the current image and run object detection


image_path = os.path.join(test_images, image_file)
detect_image = predict_detection(image_path)

axs[row, col].imshow(detect_image)
axs[row, col].axis('off')

plt.show()

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 44/47
11/9/24, 2:29 PM __notebook__

0: 1024x768 23 penguins, 59.7ms


Speed: 2.6ms preprocess, 59.7ms inference, 1.9ms postprocess per im
age at shape (1, 3, 1024, 768)

0: 1024x768 2 fishs, 1 starfish, 6.2ms


Speed: 3.0ms preprocess, 6.2ms inference, 1.7ms postprocess per ima
ge at shape (1, 3, 1024, 768)

0: 1024x768 21 penguins, 5.8ms


Speed: 2.8ms preprocess, 5.8ms inference, 1.6ms postprocess per ima
ge at shape (1, 3, 1024, 768)

0: 768x1024 11 fishs, 1 shark, 1 stingray, 56.7ms


Speed: 3.0ms preprocess, 56.7ms inference, 1.7ms postprocess per im
age at shape (1, 3, 768, 1024)

0: 1024x768 11 jellyfishs, 6.6ms


Speed: 2.4ms preprocess, 6.6ms inference, 1.7ms postprocess per ima
ge at shape (1, 3, 1024, 768)

0: 1024x768 19 jellyfishs, 6.0ms


Speed: 2.8ms preprocess, 6.0ms inference, 1.7ms postprocess per ima
ge at shape (1, 3, 1024, 768)

0: 1024x768 14 fishs, 1 shark, 5.9ms


Speed: 2.9ms preprocess, 5.9ms inference, 1.7ms postprocess per ima
ge at shape (1, 3, 1024, 768)

0: 1024x768 1 fish, 1 starfish, 5.7ms


Speed: 2.3ms preprocess, 5.7ms inference, 1.6ms postprocess per ima
ge at shape (1, 3, 1024, 768)

0: 1024x576 3 jellyfishs, 57.1ms


Speed: 2.2ms preprocess, 57.1ms inference, 1.6ms postprocess per im
age at shape (1, 3, 1024, 576)

0: 1024x768 1 fish, 1 starfish, 6.6ms


Speed: 2.5ms preprocess, 6.6ms inference, 1.7ms postprocess per ima
ge at shape (1, 3, 1024, 768)

0: 768x1024 2 fishs, 7.4ms


Speed: 3.7ms preprocess, 7.4ms inference, 1.9ms postprocess per ima
ge at shape (1, 3, 768, 1024)

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 45/47
11/9/24, 2:29 PM __notebook__

0: 1024x576 7 fishs, 1 shark, 7.4ms


Speed: 2.4ms preprocess, 7.4ms inference, 2.2ms postprocess per ima
ge at shape (1, 3, 1024, 576)

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 46/47
11/9/24, 2:29 PM __notebook__

References:

https://docs.ultralytics.com/ (https://docs.ultralytics.com/)

https://www.kaggle.com/code/vencerlanz09/wind-turbines-object-detection-using-yolov8/notebook
(https://www.kaggle.com/code/vencerlanz09/wind-turbines-object-detection-using-yolov8/notebook)

https://www.kaggle.com/code/quydau/underwater-object-detection-with-yolo-v8 47/47

You might also like