Mask R-CNN: A detailed guide with Detectron2:

Welcome to the Mask R-CNN with Detectron2 tutorial!

In this tutorial, we will jump into the workings of Mask R-CNN, a state-of-the-art framework for object instance segmentation.

We’ll be using the Detectron2 library, which provides efficient implementation of various object detection and segmentation algorithms. By the end of this tutorial, you’ll have a comprehensive understanding of how Mask R-CNN works and how to use Detectron2 to train and deploy your own instance segmentation models.

Let’s dive in!

Table of Contents:

Introducing Mask R-CNN:

Mask R-CNN is an framework that builds upon a series of developments in deep learning for computer vision to achieve state-of-the-art performance in instance segmentation tasks. Instance segmentation is the process of identifying and delineating each distinct object of interest in an image. Unlike simpler tasks such as classification (identifying what objects are present) or detection (locating objects), instance segmentation provides detailed information about the shape and exact boundaries of each object.

Foundation and Evolution:

To understand Mask R-CNN, it’s essential to trace its roots back through the evolution of related models:

R-CNN (Regions with Convolutional Neural Networks) laid the groundwork by using selective search to propose regions that might contain objects and then classifying each proposed region using CNN features.

Fast R-CNN improved efficiency by sharing computations across region proposals, using a technique called RoIPool (Region of Interest Pooling) to extract a fixed-size feature vector from each proposal.

Faster R-CNN introduced the Region Proposal Network (RPN), a fully convolutional network that predicts object bounds and objectness scores at each position. This innovation allowed the model to generate high-quality region proposals, which are then passed to a Fast R-CNN model for classification.

Understanding Mask R-CNN:

Mask R-CNN operates in two stages: the first involves generating proposals for objects within an image, and the second refines these proposals, classifying the objects and generating bounding boxes and segmentation masks. This architecture is built upon the success of Faster R-CNN but introduces a significant innovation with the mask branch, which works in parallel to the bounding box and classification branches.

Mask-R-CNN_Image

Mask-R-CNN_Image

One of the critical improvements Mask R-CNN introduces is the RoIAlign layer, which ensures that the extraction of features from each Region of Interest (RoI) is precisely aligned with the input, preserving the exact spatial locations. This precision is crucial for generating accurate masks and is a considerable improvement over the approximate spatial sampling in previous models. The approach of predicting a binary mask for each class independently, without competition among classes, is another key aspect that distinguishes Mask R-CNN.

Overview of Detectron2:

Detectron2 is a software system that implements state-of-the-art object detection algorithms, including Mask R-CNN. Developed by Facebook AI Research (FAIR), Detectron2 offers a robust and flexible framework for computer vision tasks, enabling researchers and developers to build, train, and deploy object detection models quickly.

Key features of Detectron2 include a comprehensive model zoo that provides pre-trained models for a wide variety of tasks, a modular design that allows for easy experimentation with different model architectures, and support for the latest models and algorithms in object detection.

Detectron2’s design emphasizes flexibility, allowing users to adapt the framework to their specific needs while providing a powerful toolset for developing cutting-edge computer vision applications

First, we need to install Detectron2 to make it available for use throughout the tutorial:

%pip install 'git+https://github.com/facebookresearch/detectron2.git'
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
Collecting git+https://github.com/facebookresearch/detectron2.git
  Cloning https://github.com/facebookresearch/detectron2.git to /tmp/pip-req-build-r8z815e1
  Running command git clone -q https://github.com/facebookresearch/detectron2.git /tmp/pip-req-build-r8z815e1
  Resolved https://github.com/facebookresearch/detectron2.git to commit eb96ee1d4752ff5896f623f738641fba9c755237
Requirement already satisfied: Pillow>=7.1 in /usr/local/lib/python3.10/dist-packages (from detectron2==0.6) (9.2.0)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from detectron2==0.6) (3.7.1)
Collecting pycocotools>=2.0.2
  Downloading pycocotools-2.0.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (426 kB)
     |████████████████████████████████| 426 kB 4.1 MB/s eta 0:00:01
Collecting termcolor>=1.1
  Downloading termcolor-2.4.0-py3-none-any.whl (7.7 kB)
Collecting yacs>=0.1.8
  Downloading yacs-0.1.8-py3-none-any.whl (14 kB)
Requirement already satisfied: tabulate in /usr/local/lib/python3.10/dist-packages (from detectron2==0.6) (0.9.0)
Requirement already satisfied: cloudpickle in /usr/local/lib/python3.10/dist-packages (from detectron2==0.6) (2.2.1)
Requirement already satisfied: tqdm>4.29.0 in /usr/local/lib/python3.10/dist-packages (from detectron2==0.6) (4.65.0)
Requirement already satisfied: tensorboard in /usr/local/lib/python3.10/dist-packages (from detectron2==0.6) (2.9.0)
Collecting fvcore<0.1.6,>=0.1.5
  Downloading fvcore-0.1.5.post20221221.tar.gz (50 kB)
     |████████████████████████████████| 50 kB 27.1 MB/s eta 0:00:01
Collecting iopath<0.1.10,>=0.1.7
  Downloading iopath-0.1.9-py3-none-any.whl (27 kB)
Collecting omegaconf<2.4,>=2.1
  Downloading omegaconf-2.3.0-py3-none-any.whl (79 kB)
     |████████████████████████████████| 79 kB 33.3 MB/s eta 0:00:01
Collecting hydra-core>=1.1
  Downloading hydra_core-1.3.2-py3-none-any.whl (154 kB)
     |████████████████████████████████| 154 kB 28.1 MB/s eta 0:00:01
Collecting black
  Downloading black-24.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 13.1 MB/s eta 0:00:01
Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from detectron2==0.6) (23.1)
Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from fvcore<0.1.6,>=0.1.5->detectron2==0.6) (1.22.2)
Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from fvcore<0.1.6,>=0.1.5->detectron2==0.6) (6.0)
Collecting antlr4-python3-runtime==4.9.*
  Downloading antlr4-python3-runtime-4.9.3.tar.gz (117 kB)
     |████████████████████████████████| 117 kB 21.8 MB/s eta 0:00:01
Collecting portalocker
  Downloading portalocker-2.8.2-py3-none-any.whl (17 kB)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->detectron2==0.6) (3.0.9)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->detectron2==0.6) (0.11.0)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib->detectron2==0.6) (2.8.2)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->detectron2==0.6) (1.4.4)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->detectron2==0.6) (1.0.7)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->detectron2==0.6) (4.39.3)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib->detectron2==0.6) (1.16.0)
Requirement already satisfied: typing-extensions>=4.0.1 in /usr/local/lib/python3.10/dist-packages (from black->detectron2==0.6) (4.5.0)
Collecting pathspec>=0.9.0
  Downloading pathspec-0.12.1-py3-none-any.whl (31 kB)
Requirement already satisfied: platformdirs>=2 in /usr/local/lib/python3.10/dist-packages (from black->detectron2==0.6) (3.5.1)
Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from black->detectron2==0.6) (8.1.3)
Collecting mypy-extensions>=0.4.3
  Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)
Requirement already satisfied: tomli>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from black->detectron2==0.6) (2.0.1)
Requirement already satisfied: protobuf>=3.9.2 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (3.20.3)
Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (65.5.1)
Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (2.18.1)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (1.8.1)
Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (3.4.3)
Requirement already satisfied: absl-py>=0.4 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (1.4.0)
Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (2.29.0)
Requirement already satisfied: wheel>=0.26 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (0.40.0)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (0.4.6)
Requirement already satisfied: grpcio>=1.24.3 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (1.54.2)
Requirement already satisfied: werkzeug>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (2.3.4)
Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard->detectron2==0.6) (0.6.1)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (5.3.0)
Requirement already satisfied: urllib3<2.0 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (1.26.15)
Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (4.9)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (0.3.0)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard->detectron2==0.6) (1.3.1)
Requirement already satisfied: pyasn1<0.6.0,>=0.4.6 in /usr/local/lib/python3.10/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (0.5.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.21.0->tensorboard->detectron2==0.6) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.21.0->tensorboard->detectron2==0.6) (3.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.21.0->tensorboard->detectron2==0.6) (2022.12.7)
Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.10/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard->detectron2==0.6) (3.2.2)
Requirement already satisfied: MarkupSafe>=2.1.1 in /usr/local/lib/python3.10/dist-packages (from werkzeug>=1.0.1->tensorboard->detectron2==0.6) (2.1.2)
Building wheels for collected packages: detectron2, fvcore, antlr4-python3-runtime
  Building wheel for detectron2 (setup.py) ... done
  Created wheel for detectron2: filename=detectron2-0.6-cp310-cp310-linux_x86_64.whl size=6994253 sha256=c02b81686d50dfc3c97fba529c45b746820a1a62058668174525b3c5094b2478
  Stored in directory: /tmp/pip-ephem-wheel-cache-c1hmj1f9/wheels/47/e5/15/94c80df2ba85500c5d76599cc307c0a7079d0e221bb6fc4375
  Building wheel for fvcore (setup.py) ... done
  Created wheel for fvcore: filename=fvcore-0.1.5.post20221221-py3-none-any.whl size=61429 sha256=64f3d5491bd8cf613f116509446c9ce1e2a4bcfa52d3b07c237ae760348a0e18
  Stored in directory: /tmp/pip-ephem-wheel-cache-c1hmj1f9/wheels/01/c0/af/77c1cf53a1be9e42a52b48e5af2169d40ec2e89f7362489dd0
  Building wheel for antlr4-python3-runtime (setup.py) ... done
  Created wheel for antlr4-python3-runtime: filename=antlr4_python3_runtime-4.9.3-py3-none-any.whl size=144573 sha256=12c7f7453353a390a36d6eea3a2ad89f05a8d41df56e7aa9c025efa44ec646c3
  Stored in directory: /tmp/pip-ephem-wheel-cache-c1hmj1f9/wheels/12/93/dd/1f6a127edc45659556564c5730f6d4e300888f4bca2d4c5a88
Successfully built detectron2 fvcore antlr4-python3-runtime
Installing collected packages: portalocker, antlr4-python3-runtime, yacs, termcolor, pathspec, omegaconf, mypy-extensions, iopath, pycocotools, hydra-core, fvcore, black, detectron2
  Attempting uninstall: pycocotools
    Found existing installation: pycocotools 2.0+nv0.7.3
    Uninstalling pycocotools-2.0+nv0.7.3:
      Successfully uninstalled pycocotools-2.0+nv0.7.3
Successfully installed antlr4-python3-runtime-4.9.3 black-24.3.0 detectron2-0.6 fvcore-0.1.5.post20221221 hydra-core-1.3.2 iopath-0.1.9 mypy-extensions-1.0.0 omegaconf-2.3.0 pathspec-0.12.1 portalocker-2.8.2 pycocotools-2.0.7 termcolor-2.4.0 yacs-0.1.8
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.2.4; however, version 24.0 is available.
You should consider upgrading via the '/bin/python3 -m pip install --upgrade pip' command.
Note: you may need to restart the kernel to use updated packages.

Each code snippet plays a crucial role in the process. Each code snippet will be marking with a cell number. The corresponding markdown cell will serve as the explanation for the contents of the code.

Environment and Library Setup

Cell #1 - Environment and Library Setup

Environment and Library Setup Firstly, we import essential libraries and setup the logger. This includes cv2 (OpenCV) for image operations, numpy for numerical computations, and Detectron2 specific utilities such as model_zoo, get_cfg, DefaultTrainer, and DefaultPredictor. The setup_logger() call ensures that we can see the output from Detectron2 operations.

Visualization and Data Handling Next, we import Detectron2’s visualization tools (Visualizer, ColorMode) and data handling utilities (MetadataCatalog, DatasetCatalog, build_detection_test_loader, BoxMode). These are crucial for managing our dataset’s metadata, registering our datasets for training and evaluation, and for visualizing predictions.

Evaluation Tools For evaluating our model’s performance, we use COCOEvaluator and inference_on_dataset from Detectron2’s evaluation module. Additionally, display and Image from IPython are imported for inline image display within Jupyter notebooks

#Cell 1 - Environment and Library Setup

import os
import json
import cv2
import numpy as np
import random
import requests
from detectron2 import model_zoo
from detectron2.config import get_cfg
from detectron2.engine import DefaultTrainer, DefaultPredictor
from detectron2.utils.logger import setup_logger
setup_logger()
from detectron2.utils.visualizer import Visualizer, ColorMode
from detectron2.data import MetadataCatalog, DatasetCatalog, build_detection_test_loader
from detectron2.structures import BoxMode
from detectron2.evaluation import COCOEvaluator, inference_on_dataset
from IPython.display import display, Image

Working with Pre-trained Models:

Function to Display Images in Jupyter Notebooks

We start by defining a custom function, cv2_imshow_in_notebook, specifically designed for Jupyter notebooks. This function ensures that images are properly encoded and displayed inline.

# Cell 2 - Function to display images in Jupyter notebooks
def cv2_imshow_in_notebook(img):
    _, img_encoded = cv2.imencode('.jpg', img)
    display(Image(data=img_encoded.tobytes()))

Download a Sample Image From the COCO Dataset

We acquire a sample image from the COCO dataset.The COCO (Common Objects in Context) dataset is a large-scale image recognition dataset for object detection, segmentation, and captioning tasks. It contains over 330,000 images, each annotated with 80 object categories and 5 captions describing the scene. The requests library is used to download the image, which is then loaded using OpenCV for processing.

#Cell 3 - Download a sample image from the COCO dataset
image_url = "http://images.cocodataset.org/val2017/000000037777.jpg"
image_path = "input.jpg"
r = requests.get(image_url)
with open(image_path, 'wb') as f:
    f.write(r.content)

# Load the image
im = cv2.imread(image_path)

Loading and Using Pre-trained Mask R-CNN Model

Initialize Configuration: We start with a default configuration and then load the settings for a Mask R-CNN model designed for the COCO dataset.

Set Detection Threshold: We adjust the model to only consider detections with a confidence score above 0.5 as valid.

Load Pre-trained Weights: The model is configured to use weights pre-trained on the COCO dataset, making sure there is accurate detection and segmentation.

Predictor Initialization: A DefaultPredictor is created with our settings, ready to process images.

Inference: We run inference on an image, producing predictions including object classes, bounding boxes, and segmentation masks.

#Cell 4 - Configure and load a pre-trained model from Detectron2 model zoo for demonstration
cfg_demo = get_cfg()
cfg_demo.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg_demo.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5  # set threshold for this model
cfg_demo.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
predictor_demo = DefaultPredictor(cfg_demo)
outputs_demo = predictor_demo(im)
[03/24 01:02:30 d2.checkpoint.detection_checkpoint]: [DetectionCheckpointer] Loading from https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl ...

Visualize the Prediction on the Sample Image and Display the Image With Predictions

Visualization Setup: Using Detectron2’s Visualizer, the code prepares to visualize the predictions. The image is adjusted for color display, and metadata for the dataset is provided for accurate annotation.

Drawing Predictions: It then draws the detected instances (objects and their segmentation masks) on the image. The predictions include details like bounding boxes and class labels.

Display in Notebook: Finally, the modified image, now annotated with predictions, is displayed directly in the Jupyter Notebook using a custom function that handles OpenCV image display compatibility.


#Cell 5 - Visualize the prediction on the sample image and display the image with predictions in Jupyter Notebook
v_demo = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg_demo.DATASETS.TRAIN[0]), scale=1.2)
out_demo = v_demo.draw_instance_predictions(outputs_demo["instances"].to("cpu"))

cv2_imshow_in_notebook(out_demo.get_image()[:, :, ::-1])

Training Mask R-CNN on a Custom Dataset

Downloading the Dataset

The function uses os.system() to execute a command line instruction that downloads the balloon dataset zip file from a specified URL using wget. The dataset is sourced from the official GitHub release page of the Mask R-CNN project by Matterport.

Extracting the Dataset: Following the download, another os.system() call is made to unzip the downloaded file.

#Cell 6 -Downloading the dataset

def download_and_unzip_balloon_dataset():
    os.system("wget https://github.com/matterport/Mask_RCNN/releases/download/v2.1/balloon_dataset.zip -O balloon_dataset.zip")
    os.system("unzip -o balloon_dataset.zip > /dev/null")

If you already have a dataset downloaded, you can skip the custom dataset preparation step.

This is the code you would use:

Register the dataset: register_coco_instances(“my_dataset_train”, {}, “path/to/train_annotation.json”, “path/to/train_images/”) register_coco_instances(“my_dataset_val”, {}, “path/to/val_annotation.json”, “path/to/val_images/”)

Optionally, get metadata for visualization purposes: my_dataset_metadata = MetadataCatalog.get(“my_dataset_train”)

Optionally, visualize some samples from the dataset: dataset_dicts = DatasetCatalog.get(“my_dataset_train”)

Preparing the Custom Dataset

Dataset Parsing: The get_balloon_dicts function reads dataset annotations from a JSON file (via_region_data.json). Each image and its annotations are loaded and processed.

Image Metadata Collection: For each image, metadata such as the file path, image ID, height, and width are collected. This information is essential for Detectron2 to understand how to process and display each image.

Annotation Processing: The annotations, which include points defining the polygons around each instance of the object of interest (balloons, in this case), are converted into a format compatible with Detectron2. This includes creating bounding boxes and specifying the object category.

Dataset Registration: The DatasetCatalog.register function is used to register the dataset for training and validation purposes. This step makes the dataset recognizable by Detectron2, allowing it to be used in training and evaluation workflows.

Metadata Setting: The MetadataCatalog.get(…).set(…) function assigns metadata, such as class names ([“balloon”]), to the dataset. This metadata is useful for understanding the predictions and is used in visualization.

#Cell 7 - Preparing the custom dataset

import os
from detectron2.data import DatasetCatalog, MetadataCatalog

def download_and_unzip_balloon_dataset():
    os.system("wget https://github.com/matterport/Mask_RCNN/releases/download/v2.1/balloon_dataset.zip -O balloon_dataset.zip")
    os.system("unzip -o balloon_dataset.zip > /dev/null")

def get_balloon_dicts(img_dir):
    json_file = os.path.join(img_dir, "via_region_data.json")
    with open(json_file) as f:
        imgs_anns = json.load(f)

    dataset_dicts = []
    for idx, v in enumerate(imgs_anns.values()):
        record = {}
        
        filename = os.path.join(img_dir, v["filename"])
        height, width = cv2.imread(filename).shape[:2]
        
        record["file_name"] = filename
        record["image_id"] = idx
        record["height"] = height
        record["width"] = width
      
        annos = v["regions"]
        objs = []
        for _, anno in annos.items():
            anno = anno["shape_attributes"]
            px = anno["all_points_x"]
            py = anno["all_points_y"]
            poly = [(x + 0.5, y + 0.5) for x, y in zip(px, py)]
            poly = [p for x in poly for p in x]

            obj = {
                "bbox": [np.min(px), np.min(py), np.max(px), np.max(py)],
                "bbox_mode": BoxMode.XYXY_ABS,
                "segmentation": [poly],
                "category_id": 0,
            }
            objs.append(obj)
        record["annotations"] = objs
        dataset_dicts.append(record)
    return dataset_dicts

# Download and prepare the balloon dataset
download_and_unzip_balloon_dataset()
for d in ["train", "val"]:
    DatasetCatalog.register("balloon_" + d, lambda d=d: get_balloon_dicts(f"balloon/{d}"))
    MetadataCatalog.get("balloon_" + d).set(thing_classes=["balloon"])
--2024-03-24 01:06:40--  https://github.com/matterport/Mask_RCNN/releases/download/v2.1/balloon_dataset.zip
Resolving github.com (github.com)... 140.82.112.3
Connecting to github.com (github.com)|140.82.112.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/107595270/737339e2-2b83-11e8-856a-188034eb3468?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20240324%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240324T010640Z&X-Amz-Expires=300&X-Amz-Signature=82ee15a09e26c82908fa1c14e562aba6827398b2f29a370ad5880acfdc9e9aca&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=107595270&response-content-disposition=attachment%3B%20filename%3Dballoon_dataset.zip&response-content-type=application%2Foctet-stream [following]
--2024-03-24 01:06:40--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/107595270/737339e2-2b83-11e8-856a-188034eb3468?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20240324%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240324T010640Z&X-Amz-Expires=300&X-Amz-Signature=82ee15a09e26c82908fa1c14e562aba6827398b2f29a370ad5880acfdc9e9aca&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=107595270&response-content-disposition=attachment%3B%20filename%3Dballoon_dataset.zip&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.108.133, 185.199.111.133, 185.199.110.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 38741381 (37M) [application/octet-stream]
Saving to: ‘balloon_dataset.zip’

     0K .......... .......... .......... .......... ..........  0% 2.35M 16s
    50K .......... .......... .......... .......... ..........  0% 5.14M 11s
   100K .......... .......... .......... .......... ..........  0% 5.20M 10s
   150K .......... .......... .......... .......... ..........  0% 7.35M 9s
   200K .......... .......... .......... .......... ..........  0% 6.41M 8s
   250K .......... .......... .......... .......... ..........  0% 12.7M 7s
   300K .......... .......... .......... .......... ..........  0% 6.58M 7s
   350K .......... .......... .......... .......... ..........  1% 8.63M 7s
   400K .......... .......... .......... .......... ..........  1% 8.01M 6s
   450K .......... .......... .......... .......... ..........  1% 6.31M 6s
   500K .......... .......... .......... .......... ..........  1% 7.74M 6s
   550K .......... .......... .......... .......... ..........  1% 4.35M 6s
   600K .......... .......... .......... .......... ..........  1% 6.40M 6s
   650K .......... .......... .......... .......... ..........  1% 7.58M 6s
   700K .......... .......... .......... .......... ..........  1% 7.21M 6s
   750K .......... .......... .......... .......... ..........  2% 6.69M 6s
   800K .......... .......... .......... .......... ..........  2% 4.88M 6s
   850K .......... .......... .......... .......... ..........  2% 5.20M 6s
   900K .......... .......... .......... .......... ..........  2% 11.0M 6s
   950K .......... .......... .......... .......... ..........  2% 12.1M 6s
  1000K .......... .......... .......... .......... ..........  2% 6.61M 6s
  1050K .......... .......... .......... .......... ..........  2% 4.51M 6s
  1100K .......... .......... .......... .......... ..........  3% 9.34M 6s
  1150K .......... .......... .......... .......... ..........  3% 6.17M 6s
  1200K .......... .......... .......... .......... ..........  3% 6.45M 6s
  1250K .......... .......... .......... .......... ..........  3% 5.81M 6s
  1300K .......... .......... .......... .......... ..........  3% 9.04M 6s
  1350K .......... .......... .......... .......... ..........  3% 5.70M 6s
  1400K .......... .......... .......... .......... ..........  3% 6.28M 6s
  1450K .......... .......... .......... .......... ..........  3% 6.43M 6s
  1500K .......... .......... .......... .......... ..........  4% 8.37M 6s
  1550K .......... .......... .......... .......... ..........  4% 6.87M 6s
  1600K .......... .......... .......... .......... ..........  4% 6.74M 6s
  1650K .......... .......... .......... .......... ..........  4% 6.76M 6s
  1700K .......... .......... .......... .......... ..........  4% 7.58M 6s
  1750K .......... .......... .......... .......... ..........  4% 7.08M 6s
  1800K .......... .......... .......... .......... ..........  4% 8.79M 5s
  1850K .......... .......... .......... .......... ..........  5% 6.89M 5s
  1900K .......... .......... .......... .......... ..........  5% 6.88M 5s
  1950K .......... .......... .......... .......... ..........  5% 5.77M 5s
  2000K .......... .......... .......... .......... ..........  5% 7.22M 5s
  2050K .......... .......... .......... .......... ..........  5% 7.08M 5s
  2100K .......... .......... .......... .......... ..........  5% 5.77M 5s
  2150K .......... .......... .......... .......... ..........  5% 6.77M 5s
  2200K .......... .......... .......... .......... ..........  5% 8.34M 5s
  2250K .......... .......... .......... .......... ..........  6% 6.46M 5s
  2300K .......... .......... .......... .......... ..........  6% 6.46M 5s
  2350K .......... .......... .......... .......... ..........  6% 4.90M 5s
  2400K .......... .......... .......... .......... ..........  6% 7.12M 5s
  2450K .......... .......... .......... .......... ..........  6% 5.98M 5s
  2500K .......... .......... .......... .......... ..........  6% 6.36M 5s
  2550K .......... .......... .......... .......... ..........  6% 5.99M 5s
  2600K .......... .......... .......... .......... ..........  7% 8.04M 5s
  2650K .......... .......... .......... .......... ..........  7% 5.24M 5s
  2700K .......... .......... .......... .......... ..........  7% 5.35M 5s
  2750K .......... .......... .......... .......... ..........  7% 4.34M 5s
  2800K .......... .......... .......... .......... ..........  7% 6.24M 5s
  2850K .......... .......... .......... .......... ..........  7% 4.93M 5s
  2900K .......... .......... .......... .......... ..........  7% 5.27M 5s
  2950K .......... .......... .......... .......... ..........  7% 8.87M 5s
  3000K .......... .......... .......... .......... ..........  8% 4.71M 5s
  3050K .......... .......... .......... .......... ..........  8% 8.99M 5s
  3100K .......... .......... .......... .......... ..........  8% 6.18M 5s
  3150K .......... .......... .......... .......... ..........  8% 6.20M 5s
  3200K .......... .......... .......... .......... ..........  8% 7.42M 5s
  3250K .......... .......... .......... .......... ..........  8% 5.46M 5s
  3300K .......... .......... .......... .......... ..........  8% 5.34M 5s
  3350K .......... .......... .......... .......... ..........  8% 8.93M 5s
  3400K .......... .......... .......... .......... ..........  9% 6.78M 5s
  3450K .......... .......... .......... .......... ..........  9% 5.66M 5s
  3500K .......... .......... .......... .......... ..........  9% 4.29M 5s
  3550K .......... .......... .......... .......... ..........  9% 4.84M 5s
  3600K .......... .......... .......... .......... ..........  9% 6.25M 5s
  3650K .......... .......... .......... .......... ..........  9% 8.64M 5s
  3700K .......... .......... .......... .......... ..........  9% 7.05M 5s
  3750K .......... .......... .......... .......... .......... 10% 8.16M 5s
  3800K .......... .......... .......... .......... .......... 10% 4.98M 5s
  3850K .......... .......... .......... .......... .......... 10% 7.00M 5s
  3900K .......... .......... .......... .......... .......... 10% 8.45M 5s
  3950K .......... .......... .......... .......... .......... 10% 4.65M 5s
  4000K .......... .......... .......... .......... .......... 10% 6.47M 5s
  4050K .......... .......... .......... .......... .......... 10% 7.41M 5s
  4100K .......... .......... .......... .......... .......... 10% 5.44M 5s
  4150K .......... .......... .......... .......... .......... 11% 10.3M 5s
  4200K .......... .......... .......... .......... .......... 11% 5.74M 5s
  4250K .......... .......... .......... .......... .......... 11% 5.55M 5s
  4300K .......... .......... .......... .......... .......... 11% 5.56M 5s
  4350K .......... .......... .......... .......... .......... 11% 5.37M 5s
  4400K .......... .......... .......... .......... .......... 11% 9.26M 5s
  4450K .......... .......... .......... .......... .......... 11% 6.04M 5s
  4500K .......... .......... .......... .......... .......... 12% 5.37M 5s
  4550K .......... .......... .......... .......... .......... 12% 6.10M 5s
  4600K .......... .......... .......... .......... .......... 12% 5.08M 5s
  4650K .......... .......... .......... .......... .......... 12% 6.31M 5s
  4700K .......... .......... .......... .......... .......... 12% 6.15M 5s
  4750K .......... .......... .......... .......... .......... 12% 3.94M 5s
  4800K .......... .......... .......... .......... .......... 12% 6.30M 5s
  4850K .......... .......... .......... .......... .......... 12% 5.04M 5s
  4900K .......... .......... .......... .......... .......... 13% 6.66M 5s
  4950K .......... .......... .......... .......... .......... 13% 5.70M 5s
  5000K .......... .......... .......... .......... .......... 13% 5.65M 5s
  5050K .......... .......... .......... .......... .......... 13% 5.41M 5s
  5100K .......... .......... .......... .......... .......... 13% 5.65M 5s
  5150K .......... .......... .......... .......... .......... 13% 3.40M 5s
  5200K .......... .......... .......... .......... .......... 13% 7.78M 5s
  5250K .......... .......... .......... .......... .......... 14% 5.05M 5s
  5300K .......... .......... .......... .......... .......... 14% 5.45M 5s
  5350K .......... .......... .......... .......... .......... 14% 6.35M 5s
  5400K .......... .......... .......... .......... .......... 14% 6.54M 5s
  5450K .......... .......... .......... .......... .......... 14% 5.68M 5s
  5500K .......... .......... .......... .......... .......... 14% 6.94M 5s
  5550K .......... .......... .......... .......... .......... 14% 9.36M 5s
  5600K .......... .......... .......... .......... .......... 14% 10.7M 5s
  5650K .......... .......... .......... .......... .......... 15% 46.9M 5s
  5700K .......... .......... .......... .......... .......... 15% 16.1M 5s
  5750K .......... .......... .......... .......... .......... 15% 29.1M 5s
  5800K .......... .......... .......... .......... .......... 15% 15.5M 5s
  5850K .......... .......... .......... .......... .......... 15% 14.0M 5s
  5900K .......... .......... .......... .......... .......... 15% 20.5M 5s
  5950K .......... .......... .......... .......... .......... 15% 23.4M 5s
  6000K .......... .......... .......... .......... .......... 15% 13.0M 5s
  6050K .......... .......... .......... .......... .......... 16% 16.4M 5s
  6100K .......... .......... .......... .......... .......... 16% 27.5M 5s
  6150K .......... .......... .......... .......... .......... 16% 16.9M 5s
  6200K .......... .......... .......... .......... .......... 16% 7.80M 5s
  6250K .......... .......... .......... .......... .......... 16% 19.1M 5s
  6300K .......... .......... .......... .......... .......... 16% 15.8M 5s
  6350K .......... .......... .......... .......... .......... 16% 9.66M 5s
  6400K .......... .......... .......... .......... .......... 17% 28.4M 5s
  6450K .......... .......... .......... .......... .......... 17% 17.4M 5s
  6500K .......... .......... .......... .......... .......... 17% 13.7M 5s
  6550K .......... .......... .......... .......... .......... 17% 26.5M 4s
  6600K .......... .......... .......... .......... .......... 17% 8.43M 4s
  6650K .......... .......... .......... .......... .......... 17% 43.4M 4s
  6700K .......... .......... .......... .......... .......... 17% 20.4M 4s
  6750K .......... .......... .......... .......... .......... 17% 17.1M 4s
  6800K .......... .......... .......... .......... .......... 18% 51.7M 4s
  6850K .......... .......... .......... .......... .......... 18% 19.7M 4s
  6900K .......... .......... .......... .......... .......... 18% 18.4M 4s
  6950K .......... .......... .......... .......... .......... 18% 37.7M 4s
  7000K .......... .......... .......... .......... .......... 18% 25.0M 4s
  7050K .......... .......... .......... .......... .......... 18% 21.5M 4s
  7100K .......... .......... .......... .......... .......... 18% 43.4M 4s
  7150K .......... .......... .......... .......... .......... 19% 41.3M 4s
  7200K .......... .......... .......... .......... .......... 19% 15.1M 4s
  7250K .......... .......... .......... .......... .......... 19% 8.06M 4s
  7300K .......... .......... .......... .......... .......... 19% 21.5M 4s
  7350K .......... .......... .......... .......... .......... 19% 17.3M 4s
  7400K .......... .......... .......... .......... .......... 19% 15.3M 4s
  7450K .......... .......... .......... .......... .......... 19% 51.8M 4s
  7500K .......... .......... .......... .......... .......... 19% 17.7M 4s
  7550K .......... .......... .......... .......... .......... 20% 17.5M 4s
  7600K .......... .......... .......... .......... .......... 20% 44.1M 4s
  7650K .......... .......... .......... .......... .......... 20% 8.54M 4s
  7700K .......... .......... .......... .......... .......... 20% 46.1M 4s
  7750K .......... .......... .......... .......... .......... 20% 44.2M 4s
  7800K .......... .......... .......... .......... .......... 20% 23.2M 4s
  7850K .......... .......... .......... .......... .......... 20% 46.1M 4s
  7900K .......... .......... .......... .......... .......... 21% 41.2M 4s
  7950K .......... .......... .......... .......... .......... 21% 14.5M 4s
  8000K .......... .......... .......... .......... .......... 21% 4.67M 4s
  8050K .......... .......... .......... .......... .......... 21% 11.5M 4s
  8100K .......... .......... .......... .......... .......... 21% 17.6M 4s
  8150K .......... .......... .......... .......... .......... 21% 13.6M 4s
  8200K .......... .......... .......... .......... .......... 21% 44.1M 4s
  8250K .......... .......... .......... .......... .......... 21% 19.2M 4s
  8300K .......... .......... .......... .......... .......... 22% 34.7M 4s
  8350K .......... .......... .......... .......... .......... 22% 11.9M 4s
  8400K .......... .......... .......... .......... .......... 22% 33.7M 4s
  8450K .......... .......... .......... .......... .......... 22% 23.8M 4s
  8500K .......... .......... .......... .......... .......... 22% 29.5M 4s
  8550K .......... .......... .......... .......... .......... 22% 26.4M 4s
  8600K .......... .......... .......... .......... .......... 22% 44.8M 4s
  8650K .......... .......... .......... .......... .......... 22% 22.3M 4s
  8700K .......... .......... .......... .......... .......... 23%  121M 4s
  8750K .......... .......... .......... .......... .......... 23% 15.0M 3s
  8800K .......... .......... .......... .......... .......... 23% 32.1M 3s
  8850K .......... .......... .......... .......... .......... 23% 7.07M 3s
  8900K .......... .......... .......... .......... .......... 23% 12.4M 3s
  8950K .......... .......... .......... .......... .......... 23% 12.8M 3s
  9000K .......... .......... .......... .......... .......... 23% 58.0M 3s
  9050K .......... .......... .......... .......... .......... 24% 29.0M 3s
  9100K .......... .......... .......... .......... .......... 24% 41.2M 3s
  9150K .......... .......... .......... .......... .......... 24% 10.7M 3s
  9200K .......... .......... .......... .......... .......... 24% 44.2M 3s
  9250K .......... .......... .......... .......... .......... 24% 35.5M 3s
  9300K .......... .......... .......... .......... .......... 24% 13.7M 3s
  9350K .......... .......... .......... .......... .......... 24% 38.3M 3s
  9400K .......... .......... .......... .......... .......... 24% 59.9M 3s
  9450K .......... .......... .......... .......... .......... 25% 30.6M 3s
  9500K .......... .......... .......... .......... .......... 25% 31.7M 3s
  9550K .......... .......... .......... .......... .......... 25% 28.0M 3s
  9600K .......... .......... .......... .......... .......... 25% 13.6M 3s
  9650K .......... .......... .......... .......... .......... 25% 41.3M 3s
  9700K .......... .......... .......... .......... .......... 25% 6.69M 3s
  9750K .......... .......... .......... .......... .......... 25% 4.41M 3s
  9800K .......... .......... .......... .......... .......... 26% 30.2M 3s
  9850K .......... .......... .......... .......... .......... 26% 36.0M 3s
  9900K .......... .......... .......... .......... .......... 26% 22.6M 3s
  9950K .......... .......... .......... .......... .......... 26% 12.0M 3s
 10000K .......... .......... .......... .......... .......... 26% 13.9M 3s
 10050K .......... .......... .......... .......... .......... 26% 41.9M 3s
 10100K .......... .......... .......... .......... .......... 26% 31.0M 3s
 10150K .......... .......... .......... .......... .......... 26% 32.6M 3s
 10200K .......... .......... .......... .......... .......... 27% 37.6M 3s
 10250K .......... .......... .......... .......... .......... 27% 37.9M 3s
 10300K .......... .......... .......... .......... .......... 27% 35.9M 3s
 10350K .......... .......... .......... .......... .......... 27% 38.9M 3s
 10400K .......... .......... .......... .......... .......... 27% 48.7M 3s
 10450K .......... .......... .......... .......... .......... 27% 37.9M 3s
 10500K .......... .......... .......... .......... .......... 27% 50.1M 3s
 10550K .......... .......... .......... .......... .......... 28% 16.9M 3s
 10600K .......... .......... .......... .......... .......... 28% 7.52M 3s
 10650K .......... .......... .......... .......... .......... 28% 13.5M 3s
 10700K .......... .......... .......... .......... .......... 28% 20.6M 3s
 10750K .......... .......... .......... .......... .......... 28% 23.4M 3s
 10800K .......... .......... .......... .......... .......... 28% 18.4M 3s
 10850K .......... .......... .......... .......... .......... 28% 14.0M 3s
 10900K .......... .......... .......... .......... .......... 28% 49.2M 3s
 10950K .......... .......... .......... .......... .......... 29% 19.0M 3s
 11000K .......... .......... .......... .......... .......... 29% 58.8M 3s
 11050K .......... .......... .......... .......... .......... 29% 52.6M 3s
 11100K .......... .......... .......... .......... .......... 29% 42.0M 3s
 11150K .......... .......... .......... .......... .......... 29% 25.1M 3s
 11200K .......... .......... .......... .......... .......... 29% 20.6M 3s
 11250K .......... .......... .......... .......... .......... 29% 38.7M 3s
 11300K .......... .......... .......... .......... .......... 29% 25.5M 3s
 11350K .......... .......... .......... .......... .......... 30% 11.5M 3s
 11400K .......... .......... .......... .......... .......... 30% 62.2M 3s
 11450K .......... .......... .......... .......... .......... 30% 38.9M 3s
 11500K .......... .......... .......... .......... .......... 30% 27.2M 3s
 11550K .......... .......... .......... .......... .......... 30% 16.3M 3s
 11600K .......... .......... .......... .......... .......... 30% 38.4M 3s
 11650K .......... .......... .......... .......... .......... 30% 14.2M 3s
 11700K .......... .......... .......... .......... .......... 31% 9.54M 3s
 11750K .......... .......... .......... .......... .......... 31% 38.8M 3s
 11800K .......... .......... .......... .......... .......... 31% 20.4M 3s
 11850K .......... .......... .......... .......... .......... 31% 26.6M 3s
 11900K .......... .......... .......... .......... .......... 31% 14.9M 3s
 11950K .......... .......... .......... .......... .......... 31% 17.7M 3s
 12000K .......... .......... .......... .......... .......... 31% 33.0M 3s
 12050K .......... .......... .......... .......... .......... 31% 18.1M 3s
 12100K .......... .......... .......... .......... .......... 32% 29.4M 3s
 12150K .......... .......... .......... .......... .......... 32% 52.5M 3s
 12200K .......... .......... .......... .......... .......... 32% 14.2M 3s
 12250K .......... .......... .......... .......... .......... 32% 42.8M 3s
 12300K .......... .......... .......... .......... .......... 32% 27.9M 3s
 12350K .......... .......... .......... .......... .......... 32% 19.3M 3s
 12400K .......... .......... .......... .......... .......... 32% 25.6M 3s
 12450K .......... .......... .......... .......... .......... 33% 14.7M 3s
 12500K .......... .......... .......... .......... .......... 33% 34.7M 2s
 12550K .......... .......... .......... .......... .......... 33% 25.2M 2s
 12600K .......... .......... .......... .......... .......... 33% 38.0M 2s
 12650K .......... .......... .......... .......... .......... 33% 36.6M 2s
 12700K .......... .......... .......... .......... .......... 33% 32.1M 2s
 12750K .......... .......... .......... .......... .......... 33% 25.1M 2s
 12800K .......... .......... .......... .......... .......... 33% 45.8M 2s
 12850K .......... .......... .......... .......... .......... 34% 35.6M 2s
 12900K .......... .......... .......... .......... .......... 34% 11.8M 2s
 12950K .......... .......... .......... .......... .......... 34% 45.7M 2s
 13000K .......... .......... .......... .......... .......... 34% 26.5M 2s
 13050K .......... .......... .......... .......... .......... 34% 7.80M 2s
 13100K .......... .......... .......... .......... .......... 34% 40.2M 2s
 13150K .......... .......... .......... .......... .......... 34% 12.5M 2s
 13200K .......... .......... .......... .......... .......... 35% 44.2M 2s
 13250K .......... .......... .......... .......... .......... 35% 24.5M 2s
 13300K .......... .......... .......... .......... .......... 35% 46.8M 2s
 13350K .......... .......... .......... .......... .......... 35% 11.2M 2s
 13400K .......... .......... .......... .......... .......... 35% 44.7M 2s
 13450K .......... .......... .......... .......... .......... 35% 34.6M 2s
 13500K .......... .......... .......... .......... .......... 35% 52.9M 2s
 13550K .......... .......... .......... .......... .......... 35% 22.5M 2s
 13600K .......... .......... .......... .......... .......... 36% 20.7M 2s
 13650K .......... .......... .......... .......... .......... 36% 39.7M 2s
 13700K .......... .......... .......... .......... .......... 36% 37.8M 2s
 13750K .......... .......... .......... .......... .......... 36% 28.7M 2s
 13800K .......... .......... .......... .......... .......... 36% 49.0M 2s
 13850K .......... .......... .......... .......... .......... 36% 28.8M 2s
 13900K .......... .......... .......... .......... .......... 36% 29.5M 2s
 13950K .......... .......... .......... .......... .......... 37% 21.3M 2s
 14000K .......... .......... .......... .......... .......... 37% 31.5M 2s
 14050K .......... .......... .......... .......... .......... 37% 43.9M 2s
 14100K .......... .......... .......... .......... .......... 37% 15.2M 2s
 14150K .......... .......... .......... .......... .......... 37% 40.2M 2s
 14200K .......... .......... .......... .......... .......... 37% 27.0M 2s
 14250K .......... .......... .......... .......... .......... 37% 13.5M 2s
 14300K .......... .......... .......... .......... .......... 37% 13.2M 2s
 14350K .......... .......... .......... .......... .......... 38% 34.8M 2s
 14400K .......... .......... .......... .......... .......... 38% 27.0M 2s
 14450K .......... .......... .......... .......... .......... 38% 14.4M 2s
 14500K .......... .......... .......... .......... .......... 38% 24.9M 2s
 14550K .......... .......... .......... .......... .......... 38% 21.2M 2s
 14600K .......... .......... .......... .......... .......... 38% 18.2M 2s
 14650K .......... .......... .......... .......... .......... 38% 31.6M 2s
 14700K .......... .......... .......... .......... .......... 38% 25.5M 2s
 14750K .......... .......... .......... .......... .......... 39% 19.8M 2s
 14800K .......... .......... .......... .......... .......... 39% 17.7M 2s
 14850K .......... .......... .......... .......... .......... 39% 31.8M 2s
 14900K .......... .......... .......... .......... .......... 39% 12.3M 2s
 14950K .......... .......... .......... .......... .......... 39% 12.4M 2s
 15000K .......... .......... .......... .......... .......... 39% 78.7M 2s
 15050K .......... .......... .......... .......... .......... 39% 39.5M 2s
 15100K .......... .......... .......... .......... .......... 40% 31.4M 2s
 15150K .......... .......... .......... .......... .......... 40% 24.8M 2s
 15200K .......... .......... .......... .......... .......... 40% 33.0M 2s
 15250K .......... .......... .......... .......... .......... 40% 38.1M 2s
 15300K .......... .......... .......... .......... .......... 40% 31.3M 2s
 15350K .......... .......... .......... .......... .......... 40% 27.6M 2s
 15400K .......... .......... .......... .......... .......... 40% 15.1M 2s
 15450K .......... .......... .......... .......... .......... 40% 35.9M 2s
 15500K .......... .......... .......... .......... .......... 41% 24.1M 2s
 15550K .......... .......... .......... .......... .......... 41% 27.9M 2s
 15600K .......... .......... .......... .......... .......... 41% 32.9M 2s
 15650K .......... .......... .......... .......... .......... 41% 31.8M 2s
 15700K .......... .......... .......... .......... .......... 41% 33.7M 2s
 15750K .......... .......... .......... .......... .......... 41% 27.2M 2s
 15800K .......... .......... .......... .......... .......... 41% 26.4M 2s
 15850K .......... .......... .......... .......... .......... 42% 36.8M 2s
 15900K .......... .......... .......... .......... .......... 42% 31.8M 2s
 15950K .......... .......... .......... .......... .......... 42% 17.3M 2s
 16000K .......... .......... .......... .......... .......... 42% 27.6M 2s
 16050K .......... .......... .......... .......... .......... 42% 37.3M 2s
 16100K .......... .......... .......... .......... .......... 42% 23.4M 2s
 16150K .......... .......... .......... .......... .......... 42% 25.6M 2s
 16200K .......... .......... .......... .......... .......... 42% 36.8M 2s
 16250K .......... .......... .......... .......... .......... 43% 35.8M 2s
 16300K .......... .......... .......... .......... .......... 43% 14.0M 2s
 16350K .......... .......... .......... .......... .......... 43% 31.6M 2s
 16400K .......... .......... .......... .......... .......... 43% 36.7M 2s
 16450K .......... .......... .......... .......... .......... 43% 23.4M 2s
 16500K .......... .......... .......... .......... .......... 43% 27.5M 2s
 16550K .......... .......... .......... .......... .......... 43% 40.6M 2s
 16600K .......... .......... .......... .......... .......... 44% 34.7M 2s
 16650K .......... .......... .......... .......... .......... 44% 22.4M 2s
 16700K .......... .......... .......... .......... .......... 44% 33.2M 2s
 16750K .......... .......... .......... .......... .......... 44% 17.7M 2s
 16800K .......... .......... .......... .......... .......... 44% 17.9M 2s
 16850K .......... .......... .......... .......... .......... 44% 30.4M 2s
 16900K .......... .......... .......... .......... .......... 44% 30.2M 2s
 16950K .......... .......... .......... .......... .......... 44% 38.9M 2s
 17000K .......... .......... .......... .......... .......... 45% 34.8M 2s
 17050K .......... .......... .......... .......... .......... 45% 25.2M 2s
 17100K .......... .......... .......... .......... .......... 45% 14.8M 2s
 17150K .......... .......... .......... .......... .......... 45% 20.1M 2s
 17200K .......... .......... .......... .......... .......... 45% 20.8M 2s
 17250K .......... .......... .......... .......... .......... 45% 17.8M 2s
 17300K .......... .......... .......... .......... .......... 45% 19.5M 2s
 17350K .......... .......... .......... .......... .......... 45% 39.9M 2s
 17400K .......... .......... .......... .......... .......... 46% 24.6M 2s
 17450K .......... .......... .......... .......... .......... 46% 17.8M 2s
 17500K .......... .......... .......... .......... .......... 46% 29.0M 2s
 17550K .......... .......... .......... .......... .......... 46% 15.5M 2s
 17600K .......... .......... .......... .......... .......... 46% 16.6M 2s
 17650K .......... .......... .......... .......... .......... 46% 17.2M 2s
 17700K .......... .......... .......... .......... .......... 46% 17.9M 2s
 17750K .......... .......... .......... .......... .......... 47% 38.3M 2s
 17800K .......... .......... .......... .......... .......... 47% 12.7M 2s
 17850K .......... .......... .......... .......... .......... 47% 28.1M 2s
 17900K .......... .......... .......... .......... .......... 47% 28.6M 2s
 17950K .......... .......... .......... .......... .......... 47% 19.4M 2s
 18000K .......... .......... .......... .......... .......... 47% 27.4M 2s
 18050K .......... .......... .......... .......... .......... 47% 34.5M 2s
 18100K .......... .......... .......... .......... .......... 47% 38.9M 2s
 18150K .......... .......... .......... .......... .......... 48% 32.6M 2s
 18200K .......... .......... .......... .......... .......... 48% 19.1M 2s
 18250K .......... .......... .......... .......... .......... 48% 25.6M 2s
 18300K .......... .......... .......... .......... .......... 48% 18.5M 2s
 18350K .......... .......... .......... .......... .......... 48% 28.0M 2s
 18400K .......... .......... .......... .......... .......... 48% 45.8M 2s
 18450K .......... .......... .......... .......... .......... 48% 42.7M 2s
 18500K .......... .......... .......... .......... .......... 49% 36.5M 2s
 18550K .......... .......... .......... .......... .......... 49% 37.7M 2s
 18600K .......... .......... .......... .......... .......... 49% 32.7M 2s
 18650K .......... .......... .......... .......... .......... 49% 13.9M 2s
 18700K .......... .......... .......... .......... .......... 49% 26.2M 2s
 18750K .......... .......... .......... .......... .......... 49% 15.7M 2s
 18800K .......... .......... .......... .......... .......... 49% 33.2M 1s
 18850K .......... .......... .......... .......... .......... 49% 49.5M 1s
 18900K .......... .......... .......... .......... .......... 50% 38.4M 1s
 18950K .......... .......... .......... .......... .......... 50% 40.1M 1s
 19000K .......... .......... .......... .......... .......... 50% 29.5M 1s
 19050K .......... .......... .......... .......... .......... 50% 49.2M 1s
 19100K .......... .......... .......... .......... .......... 50% 17.0M 1s
 19150K .......... .......... .......... .......... .......... 50% 45.5M 1s
 19200K .......... .......... .......... .......... .......... 50% 36.0M 1s
 19250K .......... .......... .......... .......... .......... 51% 6.58M 1s
 19300K .......... .......... .......... .......... .......... 51%  124M 1s
 19350K .......... .......... .......... .......... .......... 51%  156M 1s
 19400K .......... .......... .......... .......... .......... 51% 68.7M 1s
 19450K .......... .......... .......... .......... .......... 51% 28.4M 1s
 19500K .......... .......... .......... .......... .......... 51% 35.5M 1s
 19550K .......... .......... .......... .......... .......... 51% 24.7M 1s
 19600K .......... .......... .......... .......... .......... 51% 23.8M 1s
 19650K .......... .......... .......... .......... .......... 52% 6.70M 1s
 19700K .......... .......... .......... .......... .......... 52% 32.9M 1s
 19750K .......... .......... .......... .......... .......... 52% 29.2M 1s
 19800K .......... .......... .......... .......... .......... 52% 14.6M 1s
 19850K .......... .......... .......... .......... .......... 52% 13.8M 1s
 19900K .......... .......... .......... .......... .......... 52% 12.5M 1s
 19950K .......... .......... .......... .......... .......... 52% 23.3M 1s
 20000K .......... .......... .......... .......... .......... 52% 40.7M 1s
 20050K .......... .......... .......... .......... .......... 53% 27.1M 1s
 20100K .......... .......... .......... .......... .......... 53% 38.4M 1s
 20150K .......... .......... .......... .......... .......... 53% 36.3M 1s
 20200K .......... .......... .......... .......... .......... 53% 33.1M 1s
 20250K .......... .......... .......... .......... .......... 53% 15.5M 1s
 20300K .......... .......... .......... .......... .......... 53% 10.7M 1s
 20350K .......... .......... .......... .......... .......... 53% 34.4M 1s
 20400K .......... .......... .......... .......... .......... 54% 32.6M 1s
 20450K .......... .......... .......... .......... .......... 54% 6.37M 1s
 20500K .......... .......... .......... .......... .......... 54% 18.2M 1s
 20550K .......... .......... .......... .......... .......... 54% 31.2M 1s
 20600K .......... .......... .......... .......... .......... 54% 27.1M 1s
 20650K .......... .......... .......... .......... .......... 54% 12.2M 1s
 20700K .......... .......... .......... .......... .......... 54% 34.3M 1s
 20750K .......... .......... .......... .......... .......... 54% 8.51M 1s
 20800K .......... .......... .......... .......... .......... 55% 36.1M 1s
 20850K .......... .......... .......... .......... .......... 55% 18.7M 1s
 20900K .......... .......... .......... .......... .......... 55% 43.0M 1s
 20950K .......... .......... .......... .......... .......... 55% 41.9M 1s
 21000K .......... .......... .......... .......... .......... 55% 42.8M 1s
 21050K .......... .......... .......... .......... .......... 55% 45.5M 1s
 21100K .......... .......... .......... .......... .......... 55% 44.7M 1s
 21150K .......... .......... .......... .......... .......... 56% 29.8M 1s
 21200K .......... .......... .......... .......... .......... 56% 20.9M 1s
 21250K .......... .......... .......... .......... .......... 56% 29.2M 1s
 21300K .......... .......... .......... .......... .......... 56% 42.0M 1s
 21350K .......... .......... .......... .......... .......... 56% 9.70M 1s
 21400K .......... .......... .......... .......... .......... 56% 45.6M 1s
 21450K .......... .......... .......... .......... .......... 56% 46.8M 1s
 21500K .......... .......... .......... .......... .......... 56% 40.6M 1s
 21550K .......... .......... .......... .......... .......... 57% 46.4M 1s
 21600K .......... .......... .......... .......... .......... 57% 34.4M 1s
 21650K .......... .......... .......... .......... .......... 57% 28.9M 1s
 21700K .......... .......... .......... .......... .......... 57% 42.0M 1s
 21750K .......... .......... .......... .......... .......... 57% 42.9M 1s
 21800K .......... .......... .......... .......... .......... 57% 28.7M 1s
 21850K .......... .......... .......... .......... .......... 57% 24.1M 1s
 21900K .......... .......... .......... .......... .......... 58% 9.13M 1s
 21950K .......... .......... .......... .......... .......... 58% 47.1M 1s
 22000K .......... .......... .......... .......... .......... 58% 20.5M 1s
 22050K .......... .......... .......... .......... .......... 58% 33.7M 1s
 22100K .......... .......... .......... .......... .......... 58% 17.8M 1s
 22150K .......... .......... .......... .......... .......... 58% 46.7M 1s
 22200K .......... .......... .......... .......... .......... 58% 30.7M 1s
 22250K .......... .......... .......... .......... .......... 58% 19.3M 1s
 22300K .......... .......... .......... .......... .......... 59% 38.9M 1s
 22350K .......... .......... .......... .......... .......... 59% 40.6M 1s
 22400K .......... .......... .......... .......... .......... 59% 33.3M 1s
 22450K .......... .......... .......... .......... .......... 59% 12.3M 1s
 22500K .......... .......... .......... .......... .......... 59% 51.3M 1s
 22550K .......... .......... .......... .......... .......... 59% 29.5M 1s
 22600K .......... .......... .......... .......... .......... 59% 45.2M 1s
 22650K .......... .......... .......... .......... .......... 59% 38.5M 1s
 22700K .......... .......... .......... .......... .......... 60% 9.82M 1s
 22750K .......... .......... .......... .......... .......... 60% 39.9M 1s
 22800K .......... .......... .......... .......... .......... 60% 16.9M 1s
 22850K .......... .......... .......... .......... .......... 60% 12.2M 1s
 22900K .......... .......... .......... .......... .......... 60% 40.3M 1s
 22950K .......... .......... .......... .......... .......... 60% 33.6M 1s
 23000K .......... .......... .......... .......... .......... 60% 48.4M 1s
 23050K .......... .......... .......... .......... .......... 61% 37.8M 1s
 23100K .......... .......... .......... .......... .......... 61% 43.6M 1s
 23150K .......... .......... .......... .......... .......... 61% 25.0M 1s
 23200K .......... .......... .......... .......... .......... 61% 36.2M 1s
 23250K .......... .......... .......... .......... .......... 61% 21.6M 1s
 23300K .......... .......... .......... .......... .......... 61% 46.0M 1s
 23350K .......... .......... .......... .......... .......... 61% 13.9M 1s
 23400K .......... .......... .......... .......... .......... 61% 33.3M 1s
 23450K .......... .......... .......... .......... .......... 62% 21.5M 1s
 23500K .......... .......... .......... .......... .......... 62% 27.8M 1s
 23550K .......... .......... .......... .......... .......... 62% 34.8M 1s
 23600K .......... .......... .......... .......... .......... 62% 18.8M 1s
 23650K .......... .......... .......... .......... .......... 62% 30.0M 1s
 23700K .......... .......... .......... .......... .......... 62% 15.8M 1s
 23750K .......... .......... .......... .......... .......... 62% 48.5M 1s
 23800K .......... .......... .......... .......... .......... 63% 36.3M 1s
 23850K .......... .......... .......... .......... .......... 63% 55.8M 1s
 23900K .......... .......... .......... .......... .......... 63% 37.8M 1s
 23950K .......... .......... .......... .......... .......... 63% 42.6M 1s
 24000K .......... .......... .......... .......... .......... 63% 24.0M 1s
 24050K .......... .......... .......... .......... .......... 63% 30.3M 1s
 24100K .......... .......... .......... .......... .......... 63% 32.3M 1s
 24150K .......... .......... .......... .......... .......... 63% 38.3M 1s
 24200K .......... .......... .......... .......... .......... 64% 27.1M 1s
 24250K .......... .......... .......... .......... .......... 64% 8.68M 1s
 24300K .......... .......... .......... .......... .......... 64% 10.3M 1s
 24350K .......... .......... .......... .......... .......... 64% 11.0M 1s
 24400K .......... .......... .......... .......... .......... 64% 12.4M 1s
 24450K .......... .......... .......... .......... .......... 64% 13.8M 1s
 24500K .......... .......... .......... .......... .......... 64% 26.0M 1s
 24550K .......... .......... .......... .......... .......... 65% 23.3M 1s
 24600K .......... .......... .......... .......... .......... 65% 24.0M 1s
 24650K .......... .......... .......... .......... .......... 65% 26.4M 1s
 24700K .......... .......... .......... .......... .......... 65% 28.9M 1s
 24750K .......... .......... .......... .......... .......... 65% 26.9M 1s
 24800K .......... .......... .......... .......... .......... 65% 31.0M 1s
 24850K .......... .......... .......... .......... .......... 65% 25.3M 1s
 24900K .......... .......... .......... .......... .......... 65% 31.3M 1s
 24950K .......... .......... .......... .......... .......... 66% 34.1M 1s
 25000K .......... .......... .......... .......... .......... 66% 34.9M 1s
 25050K .......... .......... .......... .......... .......... 66% 25.7M 1s
 25100K .......... .......... .......... .......... .......... 66% 46.1M 1s
 25150K .......... .......... .......... .......... .......... 66% 41.6M 1s
 25200K .......... .......... .......... .......... .......... 66% 35.2M 1s
 25250K .......... .......... .......... .......... .......... 66% 27.5M 1s
 25300K .......... .......... .......... .......... .......... 67% 41.2M 1s
 25350K .......... .......... .......... .......... .......... 67% 35.8M 1s
 25400K .......... .......... .......... .......... .......... 67% 48.0M 1s
 25450K .......... .......... .......... .......... .......... 67% 31.7M 1s
 25500K .......... .......... .......... .......... .......... 67% 40.2M 1s
 25550K .......... .......... .......... .......... .......... 67% 36.1M 1s
 25600K .......... .......... .......... .......... .......... 67% 38.7M 1s
 25650K .......... .......... .......... .......... .......... 67% 28.9M 1s
 25700K .......... .......... .......... .......... .......... 68% 41.8M 1s
 25750K .......... .......... .......... .......... .......... 68% 39.5M 1s
 25800K .......... .......... .......... .......... .......... 68% 42.2M 1s
 25850K .......... .......... .......... .......... .......... 68% 30.2M 1s
 25900K .......... .......... .......... .......... .......... 68% 47.2M 1s
 25950K .......... .......... .......... .......... .......... 68% 30.5M 1s
 26000K .......... .......... .......... .......... .......... 68% 32.8M 1s
 26050K .......... .......... .......... .......... .......... 68% 26.7M 1s
 26100K .......... .......... .......... .......... .......... 69% 34.4M 1s
 26150K .......... .......... .......... .......... .......... 69% 38.7M 1s
 26200K .......... .......... .......... .......... .......... 69% 41.1M 1s
 26250K .......... .......... .......... .......... .......... 69% 29.3M 1s
 26300K .......... .......... .......... .......... .......... 69% 45.7M 1s
 26350K .......... .......... .......... .......... .......... 69% 35.4M 1s
 26400K .......... .......... .......... .......... .......... 69% 39.0M 1s
 26450K .......... .......... .......... .......... .......... 70% 27.8M 1s
 26500K .......... .......... .......... .......... .......... 70% 46.7M 1s
 26550K .......... .......... .......... .......... .......... 70% 35.4M 1s
 26600K .......... .......... .......... .......... .......... 70% 35.9M 1s
 26650K .......... .......... .......... .......... .......... 70% 40.9M 1s
 26700K .......... .......... .......... .......... .......... 70% 56.5M 1s
 26750K .......... .......... .......... .......... .......... 70% 38.1M 1s
 26800K .......... .......... .......... .......... .......... 70% 52.3M 1s
 26850K .......... .......... .......... .......... .......... 71% 38.4M 1s
 26900K .......... .......... .......... .......... .......... 71% 50.0M 1s
 26950K .......... .......... .......... .......... .......... 71% 44.4M 1s
 27000K .......... .......... .......... .......... .......... 71% 33.9M 1s
 27050K .......... .......... .......... .......... .......... 71% 39.7M 1s
 27100K .......... .......... .......... .......... .......... 71% 37.9M 1s
 27150K .......... .......... .......... .......... .......... 71% 42.9M 1s
 27200K .......... .......... .......... .......... .......... 72% 23.3M 1s
 27250K .......... .......... .......... .......... .......... 72% 19.6M 1s
 27300K .......... .......... .......... .......... .......... 72% 48.1M 1s
 27350K .......... .......... .......... .......... .......... 72% 47.7M 1s
 27400K .......... .......... .......... .......... .......... 72% 41.0M 1s
 27450K .......... .......... .......... .......... .......... 72% 8.33M 1s
 27500K .......... .......... .......... .......... .......... 72% 15.6M 1s
 27550K .......... .......... .......... .......... .......... 72% 53.6M 1s
 27600K .......... .......... .......... .......... .......... 73% 47.0M 1s
 27650K .......... .......... .......... .......... .......... 73% 11.6M 1s
 27700K .......... .......... .......... .......... .......... 73% 21.7M 1s
 27750K .......... .......... .......... .......... .......... 73% 37.6M 1s
 27800K .......... .......... .......... .......... .......... 73% 30.0M 1s
 27850K .......... .......... .......... .......... .......... 73% 38.0M 1s
 27900K .......... .......... .......... .......... .......... 73% 43.3M 1s
 27950K .......... .......... .......... .......... .......... 74% 9.16M 1s
 28000K .......... .......... .......... .......... .......... 74% 48.5M 1s
 28050K .......... .......... .......... .......... .......... 74% 28.9M 1s
 28100K .......... .......... .......... .......... .......... 74% 40.3M 1s
 28150K .......... .......... .......... .......... .......... 74% 9.86M 1s
 28200K .......... .......... .......... .......... .......... 74% 42.0M 1s
 28250K .......... .......... .......... .......... .......... 74% 60.0M 1s
 28300K .......... .......... .......... .......... .......... 74% 29.6M 1s
 28350K .......... .......... .......... .......... .......... 75% 39.2M 1s
 28400K .......... .......... .......... .......... .......... 75% 33.5M 1s
 28450K .......... .......... .......... .......... .......... 75% 40.8M 1s
 28500K .......... .......... .......... .......... .......... 75% 38.1M 1s
 28550K .......... .......... .......... .......... .......... 75% 44.3M 1s
 28600K .......... .......... .......... .......... .......... 75% 23.8M 1s
 28650K .......... .......... .......... .......... .......... 75% 43.4M 1s
 28700K .......... .......... .......... .......... .......... 75% 44.4M 1s
 28750K .......... .......... .......... .......... .......... 76% 34.7M 1s
 28800K .......... .......... .......... .......... .......... 76% 43.0M 1s
 28850K .......... .......... .......... .......... .......... 76% 29.4M 1s
 28900K .......... .......... .......... .......... .......... 76% 54.3M 1s
 28950K .......... .......... .......... .......... .......... 76% 7.24M 1s
 29000K .......... .......... .......... .......... .......... 76% 42.6M 1s
 29050K .......... .......... .......... .......... .......... 76% 40.5M 1s
 29100K .......... .......... .......... .......... .......... 77% 56.4M 1s
 29150K .......... .......... .......... .......... .......... 77% 28.5M 1s
 29200K .......... .......... .......... .......... .......... 77% 63.9M 1s
 29250K .......... .......... .......... .......... .......... 77% 20.4M 1s
 29300K .......... .......... .......... .......... .......... 77% 45.4M 1s
 29350K .......... .......... .......... .......... .......... 77% 39.6M 1s
 29400K .......... .......... .......... .......... .......... 77% 10.4M 1s
 29450K .......... .......... .......... .......... .......... 77% 28.4M 1s
 29500K .......... .......... .......... .......... .......... 78% 35.4M 1s
 29550K .......... .......... .......... .......... .......... 78% 23.0M 1s
 29600K .......... .......... .......... .......... .......... 78% 30.9M 1s
 29650K .......... .......... .......... .......... .......... 78% 34.2M 1s
 29700K .......... .......... .......... .......... .......... 78% 41.9M 1s
 29750K .......... .......... .......... .......... .......... 78% 20.0M 1s
 29800K .......... .......... .......... .......... .......... 78% 37.0M 1s
 29850K .......... .......... .......... .......... .......... 79% 15.6M 1s
 29900K .......... .......... .......... .......... .......... 79% 41.1M 1s
 29950K .......... .......... .......... .......... .......... 79% 32.4M 0s
 30000K .......... .......... .......... .......... .......... 79% 29.5M 0s
 30050K .......... .......... .......... .......... .......... 79% 34.6M 0s
 30100K .......... .......... .......... .......... .......... 79% 19.0M 0s
 30150K .......... .......... .......... .......... .......... 79% 15.6M 0s
 30200K .......... .......... .......... .......... .......... 79% 20.1M 0s
 30250K .......... .......... .......... .......... .......... 80% 38.3M 0s
 30300K .......... .......... .......... .......... .......... 80% 17.8M 0s
 30350K .......... .......... .......... .......... .......... 80% 38.8M 0s
 30400K .......... .......... .......... .......... .......... 80% 39.9M 0s
 30450K .......... .......... .......... .......... .......... 80% 7.16M 0s
 30500K .......... .......... .......... .......... .......... 80% 9.57M 0s
 30550K .......... .......... .......... .......... .......... 80% 14.0M 0s
 30600K .......... .......... .......... .......... .......... 81% 16.0M 0s
 30650K .......... .......... .......... .......... .......... 81% 15.9M 0s
 30700K .......... .......... .......... .......... .......... 81% 20.9M 0s
 30750K .......... .......... .......... .......... .......... 81% 7.56M 0s
 30800K .......... .......... .......... .......... .......... 81% 73.3M 0s
 30850K .......... .......... .......... .......... .......... 81% 65.9M 0s
 30900K .......... .......... .......... .......... .......... 81% 89.2M 0s
 30950K .......... .......... .......... .......... .......... 81% 44.7M 0s
 31000K .......... .......... .......... .......... .......... 82% 29.4M 0s
 31050K .......... .......... .......... .......... .......... 82% 28.2M 0s
 31100K .......... .......... .......... .......... .......... 82% 44.9M 0s
 31150K .......... .......... .......... .......... .......... 82% 32.0M 0s
 31200K .......... .......... .......... .......... .......... 82% 29.5M 0s
 31250K .......... .......... .......... .......... .......... 82% 30.0M 0s
 31300K .......... .......... .......... .......... .......... 82% 38.4M 0s
 31350K .......... .......... .......... .......... .......... 82% 31.8M 0s
 31400K .......... .......... .......... .......... .......... 83% 41.8M 0s
 31450K .......... .......... .......... .......... .......... 83% 36.4M 0s
 31500K .......... .......... .......... .......... .......... 83% 48.4M 0s
 31550K .......... .......... .......... .......... .......... 83% 36.6M 0s
 31600K .......... .......... .......... .......... .......... 83% 44.3M 0s
 31650K .......... .......... .......... .......... .......... 83% 33.8M 0s
 31700K .......... .......... .......... .......... .......... 83% 39.5M 0s
 31750K .......... .......... .......... .......... .......... 84% 48.9M 0s
 31800K .......... .......... .......... .......... .......... 84% 31.3M 0s
 31850K .......... .......... .......... .......... .......... 84% 44.7M 0s
 31900K .......... .......... .......... .......... .......... 84% 29.1M 0s
 31950K .......... .......... .......... .......... .......... 84% 61.4M 0s
 32000K .......... .......... .......... .......... .......... 84% 36.0M 0s
 32050K .......... .......... .......... .......... .......... 84% 33.4M 0s
 32100K .......... .......... .......... .......... .......... 84% 19.1M 0s
 32150K .......... .......... .......... .......... .......... 85%  127M 0s
 32200K .......... .......... .......... .......... .......... 85% 62.7M 0s
 32250K .......... .......... .......... .......... .......... 85% 28.8M 0s
 32300K .......... .......... .......... .......... .......... 85% 39.3M 0s
 32350K .......... .......... .......... .......... .......... 85% 38.2M 0s
 32400K .......... .......... .......... .......... .......... 85% 34.0M 0s
 32450K .......... .......... .......... .......... .......... 85% 30.2M 0s
 32500K .......... .......... .......... .......... .......... 86% 30.5M 0s
 32550K .......... .......... .......... .......... .......... 86% 35.3M 0s
 32600K .......... .......... .......... .......... .......... 86% 49.6M 0s
 32650K .......... .......... .......... .......... .......... 86% 41.3M 0s
 32700K .......... .......... .......... .......... .......... 86% 46.9M 0s
 32750K .......... .......... .......... .......... .......... 86% 12.1M 0s
 32800K .......... .......... .......... .......... .......... 86% 52.6M 0s
 32850K .......... .......... .......... .......... .......... 86% 23.1M 0s
 32900K .......... .......... .......... .......... .......... 87% 30.2M 0s
 32950K .......... .......... .......... .......... .......... 87% 26.7M 0s
 33000K .......... .......... .......... .......... .......... 87% 10.4M 0s
 33050K .......... .......... .......... .......... .......... 87% 44.9M 0s
 33100K .......... .......... .......... .......... .......... 87% 15.1M 0s
 33150K .......... .......... .......... .......... .......... 87% 47.1M 0s
 33200K .......... .......... .......... .......... .......... 87% 46.8M 0s
 33250K .......... .......... .......... .......... .......... 88% 34.5M 0s
 33300K .......... .......... .......... .......... .......... 88% 14.5M 0s
 33350K .......... .......... .......... .......... .......... 88% 16.4M 0s
 33400K .......... .......... .......... .......... .......... 88% 49.7M 0s
 33450K .......... .......... .......... .......... .......... 88% 38.9M 0s
 33500K .......... .......... .......... .......... .......... 88% 33.4M 0s
 33550K .......... .......... .......... .......... .......... 88% 40.9M 0s
 33600K .......... .......... .......... .......... .......... 88% 38.6M 0s
 33650K .......... .......... .......... .......... .......... 89% 42.5M 0s
 33700K .......... .......... .......... .......... .......... 89% 21.7M 0s
 33750K .......... .......... .......... .......... .......... 89% 4.43M 0s
 33800K .......... .......... .......... .......... .......... 89% 8.12M 0s
 33850K .......... .......... .......... .......... .......... 89% 8.16M 0s
 33900K .......... .......... .......... .......... .......... 89% 11.3M 0s
 33950K .......... .......... .......... .......... .......... 89% 15.7M 0s
 34000K .......... .......... .......... .......... .......... 89% 20.1M 0s
 34050K .......... .......... .......... .......... .......... 90% 16.1M 0s
 34100K .......... .......... .......... .......... .......... 90% 24.8M 0s
 34150K .......... .......... .......... .......... .......... 90% 16.5M 0s
 34200K .......... .......... .......... .......... .......... 90% 27.4M 0s
 34250K .......... .......... .......... .......... .......... 90% 24.9M 0s
 34300K .......... .......... .......... .......... .......... 90% 29.9M 0s
 34350K .......... .......... .......... .......... .......... 90% 33.7M 0s
 34400K .......... .......... .......... .......... .......... 91% 35.7M 0s
 34450K .......... .......... .......... .......... .......... 91% 26.2M 0s
 34500K .......... .......... .......... .......... .......... 91% 33.5M 0s
 34550K .......... .......... .......... .......... .......... 91% 30.9M 0s
 34600K .......... .......... .......... .......... .......... 91% 31.7M 0s
 34650K .......... .......... .......... .......... .......... 91% 23.2M 0s
 34700K .......... .......... .......... .......... .......... 91% 44.0M 0s
 34750K .......... .......... .......... .......... .......... 91% 38.7M 0s
 34800K .......... .......... .......... .......... .......... 92% 40.9M 0s
 34850K .......... .......... .......... .......... .......... 92% 32.8M 0s
 34900K .......... .......... .......... .......... .......... 92% 44.9M 0s
 34950K .......... .......... .......... .......... .......... 92% 50.8M 0s
 35000K .......... .......... .......... .......... .......... 92% 35.5M 0s
 35050K .......... .......... .......... .......... .......... 92% 41.0M 0s
 35100K .......... .......... .......... .......... .......... 92% 42.2M 0s
 35150K .......... .......... .......... .......... .......... 93% 58.5M 0s
 35200K .......... .......... .......... .......... .......... 93% 30.5M 0s
 35250K .......... .......... .......... .......... .......... 93% 26.4M 0s
 35300K .......... .......... .......... .......... .......... 93% 32.1M 0s
 35350K .......... .......... .......... .......... .......... 93% 32.0M 0s
 35400K .......... .......... .......... .......... .......... 93% 42.7M 0s
 35450K .......... .......... .......... .......... .......... 93% 28.2M 0s
 35500K .......... .......... .......... .......... .......... 93% 34.9M 0s
 35550K .......... .......... .......... .......... .......... 94% 37.8M 0s
 35600K .......... .......... .......... .......... .......... 94% 30.2M 0s
 35650K .......... .......... .......... .......... .......... 94% 33.1M 0s
 35700K .......... .......... .......... .......... .......... 94% 30.2M 0s
 35750K .......... .......... .......... .......... .......... 94% 64.3M 0s
 35800K .......... .......... .......... .......... .......... 94% 42.0M 0s
 35850K .......... .......... .......... .......... .......... 94% 31.0M 0s
 35900K .......... .......... .......... .......... .......... 95% 31.2M 0s
 35950K .......... .......... .......... .......... .......... 95% 40.6M 0s
 36000K .......... .......... .......... .......... .......... 95% 35.4M 0s
 36050K .......... .......... .......... .......... .......... 95% 28.3M 0s
 36100K .......... .......... .......... .......... .......... 95% 59.1M 0s
 36150K .......... .......... .......... .......... .......... 95% 36.5M 0s
 36200K .......... .......... .......... .......... .......... 95% 58.5M 0s
 36250K .......... .......... .......... .......... .......... 95% 39.0M 0s
 36300K .......... .......... .......... .......... .......... 96% 45.1M 0s
 36350K .......... .......... .......... .......... .......... 96% 59.2M 0s
 36400K .......... .......... .......... .......... .......... 96% 38.8M 0s
 36450K .......... .......... .......... .......... .......... 96% 33.4M 0s
 36500K .......... .......... .......... .......... .......... 96% 47.1M 0s
 36550K .......... .......... .......... .......... .......... 96% 34.6M 0s
 36600K .......... .......... .......... .......... .......... 96% 47.4M 0s
 36650K .......... .......... .......... .......... .......... 97% 35.5M 0s
 36700K .......... .......... .......... .......... .......... 97% 39.3M 0s
 36750K .......... .......... .......... .......... .......... 97% 44.2M 0s
 36800K .......... .......... .......... .......... .......... 97% 38.3M 0s
 36850K .......... .......... .......... .......... .......... 97% 31.1M 0s
 36900K .......... .......... .......... .......... .......... 97% 39.2M 0s
 36950K .......... .......... .......... .......... .......... 97% 29.6M 0s
 37000K .......... .......... .......... .......... .......... 97% 51.5M 0s
 37050K .......... .......... .......... .......... .......... 98% 49.9M 0s
 37100K .......... .......... .......... .......... .......... 98% 43.7M 0s
 37150K .......... .......... .......... .......... .......... 98% 39.7M 0s
 37200K .......... .......... .......... .......... .......... 98% 42.4M 0s
 37250K .......... .......... .......... .......... .......... 98% 31.2M 0s
 37300K .......... .......... .......... .......... .......... 98% 37.4M 0s
 37350K .......... .......... .......... .......... .......... 98% 41.7M 0s
 37400K .......... .......... .......... .......... .......... 98% 18.9M 0s
 37450K .......... .......... .......... .......... .......... 99% 52.5M 0s
 37500K .......... .......... .......... .......... .......... 99% 31.4M 0s
 37550K .......... .......... .......... .......... .......... 99% 32.4M 0s
 37600K .......... .......... .......... .......... .......... 99% 54.5M 0s
 37650K .......... .......... .......... .......... .......... 99% 21.5M 0s
 37700K .......... .......... .......... .......... .......... 99% 8.63M 0s
 37750K .......... .......... .......... .......... .......... 99% 12.3M 0s
 37800K .......... .......... .......... ...                  100% 22.9M=2.2s

2024-03-24 01:06:43 (16.8 MB/s) - ‘balloon_dataset.zip’ saved [38741381/38741381]

Model Configuration

Model Architecture: This involves choosing a specific model architecture suitable for the task at hand. We are using Mask R-CNN. The architecture is defined by a configuration file or parameters that describe the model layers, sizes, and types.

Pre-trained Weights: Utilizing pre-trained weights from a model zoo accelerates training and improves performance, especially when data is limited. These weights serve as a starting point, and Detectron2 offers access to a wide range of models pre-trained on large datasets like COCO.

Hyperparameters: Setting hyperparameters such as the learning rate, batch size, number of iterations, etc., is crucial. These parameters significantly impact the training process’s efficiency and the final model’s accuracy.

Thresholds for Detection: Defining thresholds, such as the minimum score for detecting objects, helps in filtering out less confident predictions, thus refining the results.

#Cell 8 - Configuration for the model

from detectron2.config import get_cfg
from detectron2 import model_zoo

cfg = get_cfg() #Initializes the configuration using Detectron2's default settings.
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))#Loads and merges a configuration file from the model zoo
cfg.DATASETS.TRAIN = ("balloon_train",)#Specifies the training dataset identifier.
cfg.DATASETS.TEST = ("balloon_val",)#Specifies the validation dataset identifier. These identifiers are linked to datasets that must be registered elsewhere in the code.
cfg.DATALOADER.NUM_WORKERS = 2#Sets the number of worker processes for loading data. Adjusting this can affect loading speed and training throughput
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")#Initializes the model with weights from a pre-trained model. This uses transfer learning, where a model trained on a large and general dataset (COCO) is fine-tuned for a specific task (balloon instance segmentation).
cfg.SOLVER.IMS_PER_BATCH = 2#The number of images per training batch.
cfg.SOLVER.BASE_LR = 0.00025#The base learning rate.
cfg.SOLVER.MAX_ITER = 300#The maximum number of training iterations.
cfg.SOLVER.STEPS = []
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128 #The number of region proposal objects per image during training.
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1 #ets the number of classes for the model to detect. In this case, there's only one class (balloon).
cfg.OUTPUT_DIR = './output' #Specifies the directory where output files, such as trained model checkpoints and performance metrics, will be saved.

os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)#This line of code makes sure the creation of the output directory specified in cfg.OUTPUT_DIR ('./output').

Initialize the Trainer and Start Training

The training process involves multiple epochs or iterations through the dataset, optimizing the model’s weights to minimize the loss function. Throughout the training, the trainer will utilize the dataset specified in the configuration to train the model, periodically evaluating it on the validation set (if specified) to monitor the performance.

DefaultTrainer: This is a class provided by Detectron2 designed to simplify the training process of models. It includes the complex training logic needed for computer vision tasks, such as instance segmentation, object detection, etc. The DefaultTrainer class is initialized with a configuration object (cfg) that includes all the settings and parameters for the model, the data, and the training process itself.

trainer = DefaultTrainer(cfg): This line creates an instance of the DefaultTrainer class with the specified configuration. The cfg object passed to DefaultTrainer contains all the necessary settings, including the model architecture, dataset information, hyperparameters, and other training options. This step effectively prepares the training environment with all the specified configurations.

trainer.resume_or_load(resume=False): Before starting the training, this method is called on the trainer object. Its primary purpose is to load a previously saved model or to resume training from a checkpoint.

trainer.train(): This line initiates the training process. Once this method is called, the DefaultTrainer begins training the model using the data, model architecture, and hyperparameters defined in the cfg object.


#Cell 9 - Initialize the trainer and start training

from detectron2.engine import DefaultTrainer
import json
import cv2
import numpy as np
from detectron2.structures import BoxMode

trainer = DefaultTrainer(cfg) 
trainer.resume_or_load(resume=False)
trainer.train()
[03/24 01:09:47 d2.engine.defaults]: Model:
GeneralizedRCNN(
  (backbone): FPN(
    (fpn_lateral2): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))
    (fpn_output2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (fpn_lateral3): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))
    (fpn_output3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (fpn_lateral4): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1))
    (fpn_output4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (fpn_lateral5): Conv2d(2048, 256, kernel_size=(1, 1), stride=(1, 1))
    (fpn_output5): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (top_block): LastLevelMaxPool()
    (bottom_up): ResNet(
      (stem): BasicStem(
        (conv1): Conv2d(
          3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False
          (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
        )
      )
      (res2): Sequential(
        (0): BottleneckBlock(
          (shortcut): Conv2d(
            64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv1): Conv2d(
            64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv2): Conv2d(
            64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv3): Conv2d(
            64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
        )
        (1): BottleneckBlock(
          (conv1): Conv2d(
            256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv2): Conv2d(
            64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv3): Conv2d(
            64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
        )
        (2): BottleneckBlock(
          (conv1): Conv2d(
            256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv2): Conv2d(
            64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv3): Conv2d(
            64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
        )
      )
      (res3): Sequential(
        (0): BottleneckBlock(
          (shortcut): Conv2d(
            256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv1): Conv2d(
            256, 128, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv2): Conv2d(
            128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv3): Conv2d(
            128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
        )
        (1): BottleneckBlock(
          (conv1): Conv2d(
            512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv2): Conv2d(
            128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv3): Conv2d(
            128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
        )
        (2): BottleneckBlock(
          (conv1): Conv2d(
            512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv2): Conv2d(
            128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv3): Conv2d(
            128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
        )
        (3): BottleneckBlock(
          (conv1): Conv2d(
            512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv2): Conv2d(
            128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv3): Conv2d(
            128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
        )
      )
      (res4): Sequential(
        (0): BottleneckBlock(
          (shortcut): Conv2d(
            512, 1024, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
          (conv1): Conv2d(
            512, 256, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (1): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (2): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (3): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (4): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (5): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
      )
      (res5): Sequential(
        (0): BottleneckBlock(
          (shortcut): Conv2d(
            1024, 2048, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05)
          )
          (conv1): Conv2d(
            1024, 512, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv2): Conv2d(
            512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv3): Conv2d(
            512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05)
          )
        )
        (1): BottleneckBlock(
          (conv1): Conv2d(
            2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv2): Conv2d(
            512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv3): Conv2d(
            512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05)
          )
        )
        (2): BottleneckBlock(
          (conv1): Conv2d(
            2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv2): Conv2d(
            512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv3): Conv2d(
            512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05)
          )
        )
      )
    )
  )
  (proposal_generator): RPN(
    (rpn_head): StandardRPNHead(
      (conv): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (objectness_logits): Conv2d(256, 3, kernel_size=(1, 1), stride=(1, 1))
      (anchor_deltas): Conv2d(256, 12, kernel_size=(1, 1), stride=(1, 1))
    )
    (anchor_generator): DefaultAnchorGenerator(
      (cell_anchors): BufferList()
    )
  )
  (roi_heads): StandardROIHeads(
    (box_pooler): ROIPooler(
      (level_poolers): ModuleList(
        (0): ROIAlign(output_size=(7, 7), spatial_scale=0.25, sampling_ratio=0, aligned=True)
        (1): ROIAlign(output_size=(7, 7), spatial_scale=0.125, sampling_ratio=0, aligned=True)
        (2): ROIAlign(output_size=(7, 7), spatial_scale=0.0625, sampling_ratio=0, aligned=True)
        (3): ROIAlign(output_size=(7, 7), spatial_scale=0.03125, sampling_ratio=0, aligned=True)
      )
    )
    (box_head): FastRCNNConvFCHead(
      (flatten): Flatten(start_dim=1, end_dim=-1)
      (fc1): Linear(in_features=12544, out_features=1024, bias=True)
      (fc_relu1): ReLU()
      (fc2): Linear(in_features=1024, out_features=1024, bias=True)
      (fc_relu2): ReLU()
    )
    (box_predictor): FastRCNNOutputLayers(
      (cls_score): Linear(in_features=1024, out_features=2, bias=True)
      (bbox_pred): Linear(in_features=1024, out_features=4, bias=True)
    )
    (mask_pooler): ROIPooler(
      (level_poolers): ModuleList(
        (0): ROIAlign(output_size=(14, 14), spatial_scale=0.25, sampling_ratio=0, aligned=True)
        (1): ROIAlign(output_size=(14, 14), spatial_scale=0.125, sampling_ratio=0, aligned=True)
        (2): ROIAlign(output_size=(14, 14), spatial_scale=0.0625, sampling_ratio=0, aligned=True)
        (3): ROIAlign(output_size=(14, 14), spatial_scale=0.03125, sampling_ratio=0, aligned=True)
      )
    )
    (mask_head): MaskRCNNConvUpsampleHead(
      (mask_fcn1): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (mask_fcn2): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (mask_fcn3): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (mask_fcn4): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (deconv): ConvTranspose2d(256, 256, kernel_size=(2, 2), stride=(2, 2))
      (deconv_relu): ReLU()
      (predictor): Conv2d(256, 1, kernel_size=(1, 1), stride=(1, 1))
    )
  )
)
[03/24 01:09:48 d2.data.build]: Removed 0 images with no usable annotations. 61 images left.
[03/24 01:09:48 d2.data.build]: Distribution of instances among all 1 categories:
|  category  | #instances   |
|:----------:|:-------------|
|  balloon   | 255          |
|            |              |
[03/24 01:09:48 d2.data.dataset_mapper]: [DatasetMapper] Augmentations used in training: [ResizeShortestEdge(short_edge_length=(640, 672, 704, 736, 768, 800), max_size=1333, sample_style='choice'), RandomFlip()]
[03/24 01:09:48 d2.data.build]: Using training sampler TrainingSampler
[03/24 01:09:48 d2.data.common]: Serializing the dataset using: <class 'detectron2.data.common._TorchSerializedList'>
[03/24 01:09:48 d2.data.common]: Serializing 61 elements to byte tensors and concatenating them all ...
[03/24 01:09:48 d2.data.common]: Serialized dataset takes 0.17 MiB
[03/24 01:09:48 d2.data.build]: Making batched data loader with batch_size=2
[03/24 01:09:48 d2.checkpoint.detection_checkpoint]: [DetectionCheckpointer] Loading from https://dl.fbaipublicfiles.com/detectron2/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl ...
Skip loading parameter 'roi_heads.box_predictor.cls_score.weight' to the model due to incompatible shapes: (81, 1024) in the checkpoint but (2, 1024) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.box_predictor.cls_score.bias' to the model due to incompatible shapes: (81,) in the checkpoint but (2,) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.box_predictor.bbox_pred.weight' to the model due to incompatible shapes: (320, 1024) in the checkpoint but (4, 1024) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.box_predictor.bbox_pred.bias' to the model due to incompatible shapes: (320,) in the checkpoint but (4,) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.mask_head.predictor.weight' to the model due to incompatible shapes: (80, 256, 1, 1) in the checkpoint but (1, 256, 1, 1) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.mask_head.predictor.bias' to the model due to incompatible shapes: (80,) in the checkpoint but (1,) in the model! You might want to double check if this is expected.
Some model parameters or buffers are not found in the checkpoint:
roi_heads.box_predictor.bbox_pred.{bias, weight}
roi_heads.box_predictor.cls_score.{bias, weight}
roi_heads.mask_head.predictor.{bias, weight}
[03/24 01:09:48 d2.engine.train_loop]: Starting training from iteration 0
/usr/local/lib/python3.10/dist-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at /opt/pytorch/pytorch/aten/src/ATen/native/TensorShape.cpp:3483.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
[03/24 01:10:10 d2.utils.events]:  eta: 0:04:40  iter: 19  total_loss: 2.065  loss_cls: 0.6864  loss_box_reg: 0.548  loss_mask: 0.6894  loss_rpn_cls: 0.04892  loss_rpn_loc: 0.006012    time: 0.9925  last_time: 0.8960  data_time: 0.0228  last_data_time: 0.0034   lr: 1.6068e-05  max_mem: 2738M
[03/24 01:10:30 d2.utils.events]:  eta: 0:04:19  iter: 39  total_loss: 1.878  loss_cls: 0.5938  loss_box_reg: 0.6185  loss_mask: 0.6034  loss_rpn_cls: 0.02946  loss_rpn_loc: 0.005873    time: 0.9980  last_time: 1.1743  data_time: 0.0075  last_data_time: 0.0095   lr: 3.2718e-05  max_mem: 2738M
[03/24 01:10:51 d2.utils.events]:  eta: 0:03:59  iter: 59  total_loss: 1.611  loss_cls: 0.4638  loss_box_reg: 0.6267  loss_mask: 0.4823  loss_rpn_cls: 0.03451  loss_rpn_loc: 0.003271    time: 1.0144  last_time: 1.1730  data_time: 0.0073  last_data_time: 0.0038   lr: 4.9367e-05  max_mem: 2750M
[03/24 01:11:12 d2.utils.events]:  eta: 0:03:40  iter: 79  total_loss: 1.489  loss_cls: 0.368  loss_box_reg: 0.6775  loss_mask: 0.3813  loss_rpn_cls: 0.01245  loss_rpn_loc: 0.007338    time: 1.0203  last_time: 0.8949  data_time: 0.0084  last_data_time: 0.0125   lr: 6.6017e-05  max_mem: 2750M
[03/24 01:11:34 d2.utils.events]:  eta: 0:03:22  iter: 99  total_loss: 1.22  loss_cls: 0.2809  loss_box_reg: 0.6749  loss_mask: 0.2885  loss_rpn_cls: 0.02219  loss_rpn_loc: 0.007728    time: 1.0321  last_time: 0.9512  data_time: 0.0146  last_data_time: 0.0164   lr: 8.2668e-05  max_mem: 2750M
[03/24 01:11:56 d2.utils.events]:  eta: 0:03:04  iter: 119  total_loss: 1.126  loss_cls: 0.2496  loss_box_reg: 0.5879  loss_mask: 0.2272  loss_rpn_cls: 0.02268  loss_rpn_loc: 0.009278    time: 1.0457  last_time: 0.9841  data_time: 0.0126  last_data_time: 0.0182   lr: 9.9318e-05  max_mem: 2841M
[03/24 01:12:17 d2.utils.events]:  eta: 0:02:45  iter: 139  total_loss: 1.088  loss_cls: 0.2045  loss_box_reg: 0.6462  loss_mask: 0.1918  loss_rpn_cls: 0.03709  loss_rpn_loc: 0.01279    time: 1.0502  last_time: 1.1140  data_time: 0.0120  last_data_time: 0.0078   lr: 0.00011597  max_mem: 2841M
[03/24 01:12:38 d2.utils.events]:  eta: 0:02:24  iter: 159  total_loss: 0.7912  loss_cls: 0.1295  loss_box_reg: 0.4954  loss_mask: 0.111  loss_rpn_cls: 0.007541  loss_rpn_loc: 0.004359    time: 1.0478  last_time: 1.0345  data_time: 0.0104  last_data_time: 0.0046   lr: 0.00013262  max_mem: 2842M
[03/24 01:12:59 d2.utils.events]:  eta: 0:02:04  iter: 179  total_loss: 0.7232  loss_cls: 0.1283  loss_box_reg: 0.4466  loss_mask: 0.146  loss_rpn_cls: 0.02093  loss_rpn_loc: 0.01081    time: 1.0468  last_time: 1.0894  data_time: 0.0089  last_data_time: 0.0076   lr: 0.00014927  max_mem: 2842M
[03/24 01:13:21 d2.utils.events]:  eta: 0:01:43  iter: 199  total_loss: 0.5111  loss_cls: 0.1041  loss_box_reg: 0.3098  loss_mask: 0.0884  loss_rpn_cls: 0.01099  loss_rpn_loc: 0.006714    time: 1.0518  last_time: 1.0038  data_time: 0.0094  last_data_time: 0.0053   lr: 0.00016592  max_mem: 2842M
[03/24 01:13:41 d2.utils.events]:  eta: 0:01:22  iter: 219  total_loss: 0.4182  loss_cls: 0.07609  loss_box_reg: 0.2185  loss_mask: 0.0854  loss_rpn_cls: 0.01286  loss_rpn_loc: 0.006843    time: 1.0490  last_time: 1.0151  data_time: 0.0088  last_data_time: 0.0046   lr: 0.00018257  max_mem: 2842M
[03/24 01:14:03 d2.utils.events]:  eta: 0:01:02  iter: 239  total_loss: 0.3773  loss_cls: 0.07422  loss_box_reg: 0.1823  loss_mask: 0.08169  loss_rpn_cls: 0.00807  loss_rpn_loc: 0.006176    time: 1.0522  last_time: 0.9854  data_time: 0.0100  last_data_time: 0.0097   lr: 0.00019922  max_mem: 2842M
[03/24 01:14:24 d2.utils.events]:  eta: 0:00:41  iter: 259  total_loss: 0.3635  loss_cls: 0.07033  loss_box_reg: 0.1717  loss_mask: 0.07367  loss_rpn_cls: 0.01738  loss_rpn_loc: 0.005297    time: 1.0520  last_time: 1.1337  data_time: 0.0092  last_data_time: 0.0117   lr: 0.00021587  max_mem: 2842M
[03/24 01:14:45 d2.utils.events]:  eta: 0:00:20  iter: 279  total_loss: 0.3828  loss_cls: 0.08961  loss_box_reg: 0.1605  loss_mask: 0.1044  loss_rpn_cls: 0.007527  loss_rpn_loc: 0.008889    time: 1.0528  last_time: 1.0041  data_time: 0.0094  last_data_time: 0.0155   lr: 0.00023252  max_mem: 2842M
[03/24 01:15:10 d2.utils.events]:  eta: 0:00:00  iter: 299  total_loss: 0.3096  loss_cls: 0.07114  loss_box_reg: 0.1505  loss_mask: 0.07772  loss_rpn_cls: 0.009302  loss_rpn_loc: 0.006894    time: 1.0543  last_time: 1.1920  data_time: 0.0115  last_data_time: 0.0112   lr: 0.00024917  max_mem: 2842M
[03/24 01:15:11 d2.engine.hooks]: Overall training speed: 298 iterations in 0:05:14 (1.0543 s / it)
[03/24 01:15:11 d2.engine.hooks]: Total training time: 0:05:18 (0:00:04 on hooks)
[03/24 01:15:11 d2.data.build]: Distribution of instances among all 1 categories:
|  category  | #instances   |
|:----------:|:-------------|
|  balloon   | 50           |
|            |              |
[03/24 01:15:11 d2.data.dataset_mapper]: [DatasetMapper] Augmentations used in inference: [ResizeShortestEdge(short_edge_length=(800, 800), max_size=1333, sample_style='choice')]
[03/24 01:15:11 d2.data.common]: Serializing the dataset using: <class 'detectron2.data.common._TorchSerializedList'>
[03/24 01:15:11 d2.data.common]: Serializing 13 elements to byte tensors and concatenating them all ...
[03/24 01:15:11 d2.data.common]: Serialized dataset takes 0.04 MiB
WARNING [03/24 01:15:11 d2.engine.defaults]: No evaluator found. Use `DefaultTrainer.test(evaluators=)`, or implement its `build_evaluator` method.

Evaluation

The evaluation results indicate the model’s performance on the validation dataset. The average precision (AP) scores at different Intersection over Union (IoU) thresholds and object sizes are reported.

Here’s a summary of the results:

Bounding Box AP: The average precision for bounding box detection ranges from 78.99% to 91.66% across different IoU thresholds and object sizes. This indicates the accuracy of object localization.

Segmentation AP: The average precision for instance segmentation ranges from 81.74% to 95.99%, indicating the accuracy of both object localization and pixel-wise segmentation.

Code Explanation:

inference_on_dataset(trainer.model, val_loader, evaluator): This function performs the actual evaluation. It takes the trained model (trainer.model), the validation data loader (val_loader), and the COCOEvaluator instance (evaluator). The function passes the validation dataset through the trained model to make predictions, then compares these predictions against the true labels to compute the evaluation metrics specified by the COCOEvaluator (e.g., precision, recall, mAP).

COCOEvaluator(“balloon_val”, cfg, False, output_dir=cfg.OUTPUT_DIR): This creates an instance of the COCOEvaluator, which is a class provided by Detectron2 for evaluating model performance using COCO metrics.

build_detection_test_loader(cfg, “balloon_val”): This function prepares the data loader for the validation dataset. It uses the configuration (cfg) to understand how to process the data and “balloon_val” to specify which dataset to load.

#Cell 10 - Evaluation

from detectron2.evaluation import COCOEvaluator
from detectron2.data import build_detection_test_loader
from detectron2.evaluation import inference_on_dataset

evaluator = COCOEvaluator("balloon_val", cfg, False, output_dir=cfg.OUTPUT_DIR)
val_loader = build_detection_test_loader(cfg, "balloon_val")
inference_on_dataset(trainer.model, val_loader, evaluator)
WARNING [03/24 01:17:29 d2.evaluation.coco_evaluation]: COCO Evaluator instantiated using config, this is deprecated behavior. Please pass in explicit arguments instead.
[03/24 01:17:30 d2.data.dataset_mapper]: [DatasetMapper] Augmentations used in inference: [ResizeShortestEdge(short_edge_length=(800, 800), max_size=1333, sample_style='choice')]
[03/24 01:17:30 d2.data.common]: Serializing the dataset using: <class 'detectron2.data.common._TorchSerializedList'>
[03/24 01:17:30 d2.data.common]: Serializing 13 elements to byte tensors and concatenating them all ...
[03/24 01:17:30 d2.data.common]: Serialized dataset takes 0.04 MiB
[03/24 01:17:30 d2.evaluation.evaluator]: Start inference on 13 batches
[03/24 01:17:50 d2.evaluation.evaluator]: Inference done 3/13. Dataloading: 0.0746 s/iter. Inference: 6.5513 s/iter. Eval: 0.3164 s/iter. Total: 6.9430 s/iter. ETA=0:01:09
[03/24 01:17:57 d2.evaluation.evaluator]: Inference done 11/13. Dataloading: 0.0026 s/iter. Inference: 0.2846 s/iter. Eval: 0.0363 s/iter. Total: 0.3235 s/iter. ETA=0:00:00
[03/24 01:17:58 d2.evaluation.evaluator]: Total inference time: 0:00:02.553590 (0.319199 s / iter per device, on 1 devices)
[03/24 01:17:58 d2.evaluation.evaluator]: Total inference pure compute time: 0:00:02 (0.281935 s / iter per device, on 1 devices)
[03/24 01:17:58 d2.evaluation.coco_evaluation]: Preparing results for COCO format ...
[03/24 01:17:58 d2.evaluation.coco_evaluation]: Saving results to ./output/coco_instances_results.json
[03/24 01:17:58 d2.evaluation.coco_evaluation]: Evaluating predictions with unofficial COCO API...
Loading and preparing results...
DONE (t=0.00s)
creating index...
index created!
[03/24 01:17:58 d2.evaluation.fast_eval_api]: Evaluate annotation type *bbox*
[03/24 01:17:58 d2.evaluation.fast_eval_api]: COCOeval_opt.evaluate() finished in 0.01 seconds.
[03/24 01:17:58 d2.evaluation.fast_eval_api]: Accumulating evaluation results...
[03/24 01:17:58 d2.evaluation.fast_eval_api]: COCOeval_opt.accumulate() finished in 0.00 seconds.
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.790
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.917
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.855
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.330
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.617
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.910
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.236
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.806
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.832
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.467
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.729
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.927
[03/24 01:17:58 d2.evaluation.coco_evaluation]: Evaluation results for bbox: 
|   AP   |  AP50  |  AP75  |  APs   |  APm   |  APl   |
|:------:|:------:|:------:|:------:|:------:|:------:|
| 78.989 | 91.663 | 85.452 | 33.020 | 61.692 | 90.968 |
Loading and preparing results...
DONE (t=0.01s)
creating index...
index created!
[03/24 01:17:58 d2.evaluation.fast_eval_api]: Evaluate annotation type *segm*
[03/24 01:17:58 d2.evaluation.fast_eval_api]: COCOeval_opt.evaluate() finished in 0.01 seconds.
[03/24 01:17:58 d2.evaluation.fast_eval_api]: Accumulating evaluation results...
[03/24 01:17:58 d2.evaluation.fast_eval_api]: COCOeval_opt.accumulate() finished in 0.00 seconds.
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.817
 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.895
 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.893
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.248
 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.611
 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.960
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.252
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.828
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.858
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.400
 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.741
 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.970
[03/24 01:17:58 d2.evaluation.coco_evaluation]: Evaluation results for segm: 
|   AP   |  AP50  |  AP75  |  APs   |  APm   |  APl   |
|:------:|:------:|:------:|:------:|:------:|:------:|
| 81.740 | 89.506 | 89.264 | 24.774 | 61.068 | 95.985 |
OrderedDict([('bbox',
              {'AP': 78.98890588016866,
               'AP50': 91.6628378658105,
               'AP75': 85.4515658706337,
               'APs': 33.019801980198025,
               'APm': 61.69169662323899,
               'APl': 90.96802583484155}),
             ('segm',
              {'AP': 81.74023471226421,
               'AP50': 89.50621611714344,
               'AP75': 89.26384813034474,
               'APs': 24.77447744774478,
               'APm': 61.06832736811009,
               'APl': 95.9853048112693})])

Setup Cfg for Inference

The inference section prepares the trained model for making predictions on new images by loading the trained weights and setting up inference parameters like the score threshold. After this setup, you can use the predictor object to perform inference on unseen images.

cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, “model_final.pth”): This line specifies the path to the weights of the trained model. os.path.join(cfg.OUTPUT_DIR, “model_final.pth”) tells Detectron2 where to find the trained model so it can be loaded for making predictions.

cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.7: Here, the threshold for considering a detection to be valid during testing is set to 0.7. This means that any detection with a confidence score lower than 0.7 will be ignored. Adjusting this threshold can help balance between precision and recall, depending on the requirements of your specific application. A higher threshold generally leads to higher precision but lower recall, as fewer detections are considered confident enough.

predictor = DefaultPredictor(cfg): An instance of DefaultPredictor is created with the updated configuration. DefaultPredictor is a class provided by Detectron2 that simplifies making predictions with a trained model. It takes care of model loading and setting up the data pipeline for feeding images into the model.

#Cell 11 - Setup cfg for inference
from detectron2.engine import DefaultPredictor

cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, "model_final.pth") # path to the model we just trained
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.7   # set a custom testing threshold
predictor = DefaultPredictor(cfg)
[03/24 01:21:50 d2.checkpoint.detection_checkpoint]: [DetectionCheckpointer] Loading from ./output/model_final.pth ...

Visualizing Model Predictions on Validation Data

Visualize the Prediction: A Visualizer instance is created with the image and metadata for the validation dataset. The instance_mode=ColorMode.IMAGE_BW argument ensures that unsegmented pixels are not colored, focusing attention on the segmented objects.

The visualized output is temporarily saved to a file, which is then displayed in the Jupyter Notebook using display(Image(filename=tmpfile.name)).

outputs = predictor(im) uses the previously configured predictor to detect objects in the loaded image, producing predictions that include object classes, bounding boxes, and masks.

After displaying, the temporary file is deleted with os.unlink(tmpfile.name) to clean up and free resources.

#Cell 12 - Visualizing model predictions on validation data

import random
from detectron2.utils.visualizer import Visualizer
from detectron2.utils.visualizer import ColorMode


# Load a random image from the validation set
dataset_dicts = get_balloon_dicts("balloon/val")
d = random.choice(dataset_dicts)
im = cv2.imread(d["file_name"])
outputs = predictor(im)

# Visualize the prediction
v = Visualizer(im[:, :, ::-1], metadata=MetadataCatalog.get("balloon_val"), scale= 0.5, instance_mode=ColorMode.IMAGE_BW)  # remove the colors of unsegmented pixels
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))

# Display the image - adapt for Jupyter Notebook or standalone Python script as needed
from IPython.display import display, Image
import tempfile

# Create a temporary file to save the visualized output
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as tmpfile:
    cv2.imwrite(tmpfile.name, out.get_image()[:, :, ::-1])
    # Display in Jupyter Notebook
    display(Image(filename=tmpfile.name))


# Cleanup the tempfile if necessary
os.unlink(tmpfile.name)

Conclusion

Congratulations on completing the Mask R-CNN with Detectron2 tutorial!

We’ve covered a lot of content, from understanding the theoretical underpinnings of Mask R-CNN to implementing it using the Detectron2 library.

I hope this tutorial has provided you with a solid foundation and equipped you with the knowledge and tools to explore further on your own.

Back to top