Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

3.7 Ice Seal Classification using YOLO26

Open In Colab

Overview

In this lesson, we will train a YOLO26 classification model on images of ice-associated seals from the NOAA Alaska Fisheries Science Center. These 640x640 images have been extracted from aerial photography using a separate ROI object detector. Due to the small size of the original imagery, individual seals cannot be identified with an adequate level of detail in a single pass. This necessitates a two-shot detection approach, where the first stage (the ROI object detector) localizes potential seals, and the second stage (the classifier) refines the identification at the species level. The dataset includes the following classes:

bearded_pup bearded_seal ribbon_pup ribbon_seal ringed_pup ringed_seal spotted_pup spotted_seal unknown_pup unknown_seal After training the model, we will run inference on a folder (named transect) containing images of unknown seals. The aggregated predictions will then be visualized using heatmaps and stacked area plots to explore species distribution and ecological relationships.

Learning Objectives

  • Train a YOLO26 classification model on marine seal images.

  • Evaluate the model’s performance using standard metrics.

  • Perform inference on a transect folder of unknown seal images.

  • Aggregate and visualize predictions using heatmaps and stacked area plots.

  • Interpret the ecological relationships and species distributions from the visualization.

Dataset Description

The dataset comprises 640x640 images of ice-associated seals with the following distribution:

  • bearded_pup: 336 images

  • bearded_seal: 1537 images

  • ribbon_pup: 28 images

  • ribbon_seal: 185 images

  • ringed_pup: 43 images

  • ringed_seal: 2542 images

  • spotted_pup: 190 images

  • spotted_seal: 1329 images

  • unknown_pup: 313 images

  • unknown_seal: 648 images

Each image file follows a naming convention (e.g., 100_bearded_pup.jpg). Ensure that the dataset is organized and the paths are correctly set in your configuration file (data.yaml).

Download the dataset here: https://huggingface.co/datasets/atticus-carter/NOAA_AFSC_MML_Iceseals_Classification/blob/main/640_yolo_classification_dataset.zip

Download the secret transect here: https://huggingface.co/datasets/atticus-carter/NOAA_AFSC_MML_Iceseals_Transects/blob/main/transect_mystery.zip

Preparing the Environment

Before starting, make sure you are using a GPU-enabled runtime. Run the cell below to check your GPU status.

Environment Setup

Install the Ultralytics package, which provides the YOLO framework including the classification variant (YOLO26c). This also installs PyTorch, torchvision, and other dependencies. If running on Colab, verify GPU availability first by checking the output of nvidia-smi above: training on CPU is possible but will be substantially slower for any dataset of realistic size.

Imports

Import the core libraries. YOLO loads and manages the model, handling weight download, training configuration, and inference in a single interface. os handles directory traversal when running inference across transect subfolders, where each subdirectory represents a 100-meter survey segment. pandas and numpy support aggregating per-segment prediction counts and computing summary statistics, while matplotlib and seaborn turn those aggregates into the species-distribution plots you will generate at the end of the notebook.

Then unzip your dataset:

Training the Classification Model

The following code trains the YOLO26 classification model using the provided marine seal dataset. The model will be trained for 100 epochs with an image size of 640 pixels. Make sure the training configuration (e.g., class labels and paths) is correctly specified in your data.yaml file. Optionally you can configure your tensorboard now if you prefer to visualize metrics with it.

Assessing Model Performance

Review the output images displayed above to assess the model’s performance. Pay close attention to per-class metrics and overall performance indicators such as the F1 score, precision-recall curves, and confusion matrices. These visuals will help you identify which classes are performing well and where improvements might be needed.

Inference on the Transect Folder

The transect folder is organized into subfolders representing every 100 meters along a 3km transect (e.g., 0m, 100m, 200m, …, 3000m). Each subfolder contains ROI detection images from that segment. The code below traverses each subfolder, runs inference on all JPEG images within, and saves the resulting prediction images. It also aggregates the classification probabilities for later visualization.

Visualizing Transect Predictions

We now aggregate the predictions from each 100m segment. For each segment, we compute the mean probability for each species and then visualize these aggregated predictions using a heatmap, stacked area plot and stacked bar chart. This data was cleaned to remove erroneous ROIs via a simple clustering review system.