{ "cells": [ { "cell_type": "markdown", "id": "0263cedb", "metadata": {}, "source": [ "# 2D Segmentation with the Datamint Trainer API\n", "\n", "This notebook shows how to train **DeepLab V3+, UNet++ and TransUNet semantic segmentation** model on the **BUSI** (Breast Ultrasound Images) dataset using Datamint's **Trainer API** — a high-level wrapper that handles dataset loading, model creation, training, experiment tracking, and model registration from a small amount of code.\n", "\n", "## Comparison with the manual Workflow\n", "\n", "The conventional way requires you to:\n", "1. Define transforms, loss function, metrics, and a full LightningModule (~150 lines)\n", "2. Configure MLflow logger, callbacks, and Trainer (~50 lines)\n", "3. Build and wire together `DatamintDataModule`, `L.Trainer`, etc.\n", "\n", "With the Trainer API, **all of that is replaced by ~3 lines**:\n", "\n", "```python\n", "from datamint.lightning.trainers import DeepLabV3PlusTrainer\n", "\n", "trainer = DeepLabV3PlusTrainer(project='MyProject')\n", "results = trainer.fit()\n", "```\n", "\n", "The same applies to the other models.\n", "\n", "\n", "## What You'll Learn\n", "\n", "1. Upload data to Datamint\n", "2. Train with `DeepLabV3PlusTrainer`, `UNetPPTrainer`, `TransUNetTrainer` using **zero configuration**\n", "3. Train with `SemanticSegmentation2DTrainer` while swapping in a custom external model\n", "4. Visualise predictions\n", "5. Register and deploy the trained model\n", "\n", "## Required Dependencies\n", "\n", "```bash\n", "pip install datamint\n", "```" ] }, { "cell_type": "code", "execution_count": null, "id": "ca7b0298", "metadata": {}, "outputs": [], "source": [ "from datamint import Api\n", "\n", "PROJECT_NAME = \"deeplabv3plus_Segmentation_Tutorial\"\n", "api = Api()" ] }, { "cell_type": "markdown", "id": "19abf11f", "metadata": {}, "source": [ "## 1. Setup: Create Project and Load Dataset\n", "\n", "`datamint.examples.busi_dataset` downloads the [BUSI breast-ultrasound dataset](https://www.kaggle.com/datasets/sabahesaraki/breast-ultrasound-images-dataset), uploads the images to a Datamint project (tagged `busi`), and uploads the lesion segmentation masks for the `benign` / `malignant` classes. The call is idempotent — if the project already exists, it's returned as-is without re-uploading." ] }, { "cell_type": "code", "execution_count": 2, "id": "af13262e", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING:datamint.examples.busi_dataset:Project 'deeplabv3plus_Segmentation_Tutorial' already exists. Skipping data population.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "BUSI Segmentation Example\n", " project 'deeplabv3plus_Segmentation_Tutorial' already exists, skipping data population.\n", " https://app.datamint.io/projects/edit/6f0c4ccb-8dda-41c1-be60-144e4953270c\n" ] }, { "data": { "text/html": [ "
| Name | \n", "\n", " deeplabv3plus_Segmentation_Tutorial\n", " | \n", "
|---|---|
| Created At | \n", "\n", " 2026-06-01T12:48:44.168Z\n", " | \n", "
| Created By | \n", "\n", " lucasmello.research@gmail.com\n", " | \n", "
| Archived | \n", "\n", " False\n", " | \n", "
| Resource Count | \n", "\n", " 780\n", " | \n", "