From 4c4754d31caf943e92620ff06a8d7d6567a6f23a Mon Sep 17 00:00:00 2001 From: Anwai Archit <52396323+anwai98@users.noreply.github.com> Date: Sun, 5 May 2024 10:57:19 +0200 Subject: [PATCH] Add batched inference and evaluation notebook (#586) --- notebooks/inference_sam.ipynb | 1894 +++++++++++++++++++++++++++++++++ 1 file changed, 1894 insertions(+) create mode 100644 notebooks/inference_sam.ipynb diff --git a/notebooks/inference_sam.ipynb b/notebooks/inference_sam.ipynb new file mode 100644 index 00000000..6c369a44 --- /dev/null +++ b/notebooks/inference_sam.ipynb @@ -0,0 +1,1894 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Evaluating Segment Anything (SAM)\n", + "\n", + "Here is an example for evaluating the automatic and interactive segmentation capability of SAM and `µsam` on differential interference contrast microscopic images from the Cell Tracking Challenge (DIC-C2DH-HeLa: HeLa cells on a flat glass - https://doi.org/10.1038/s41592-023-01879-y).\n", + "\n", + "With the scripts below, you can validate the quality of the Segment Anything models to perform interactive segmentation.\n", + "\n", + "We compare three settings in batched mode for all images:\n", + "1. Automatic Mask Generation (AMG): The \"Segment Anything\" feature where a grid of positive point prompts are sampled over the entire image to perform instance segmentation.\n", + "2. Automatic Instance Segmentation (AIS): The feature in `µsam` (Segment Anything for Microscopy) where we introduce an additional decoder to perform automatic instance segmentation.\n", + "3. Interactive Segmentation using Input Prompts derived from ground-truth objects." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Let's check, where are you now?\n", + "\n", + "**NOTE**: The scripts have been tested on our recommended open-source cloud servers, [Kaggle Notebooks](https://www.kaggle.com/code/)." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", + "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5", + "execution": { + "iopub.execute_input": "2024-05-04T21:44:14.064291Z", + "iopub.status.busy": "2024-05-04T21:44:14.063977Z", + "iopub.status.idle": "2024-05-04T21:44:14.078175Z", + "shell.execute_reply": "2024-05-04T21:44:14.077125Z", + "shell.execute_reply.started": "2024-05-04T21:44:14.064252Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Kaggle says hi!\n" + ] + } + ], + "source": [ + "import os\n", + "current_spot = os.getcwd()\n", + "\n", + "if current_spot.startswith(\"/kaggle/working\"):\n", + " using_kaggle = True\n", + " print(\"Kaggle says hi!\")\n", + " root_dir = \"/kaggle/working\"\n", + "\n", + "else:\n", + " if current_spot.startswith(\"/content\"):\n", + " using_colab = True\n", + " print(\"Google Colab says hi!\")\n", + " print(\" NOTE: The scripts have not been tested on Google Colab, you might need to adapt the installations a bit.\")\n", + " root_dir = \"/content\"\n", + "\n", + " # You might need to install condacolab on Google Colab to be able to install packages using conda / mamba\n", + " # !pip install -q condacolab\n", + " # import condacolab\n", + " # condacolab.install()\n", + " \n", + " else:\n", + " msg = \"You are using a behind-the-scenes resource. Follow our installation instructions here:\"\n", + " msg += \" https://computational-cell-analytics.github.io/micro-sam/micro_sam.html#installation\"\n", + " print(msg)\n", + " root_dir = \"\" # overwrite to set the root directory, where the data, checkpoints, and all relevant stuff will be stored" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Installation\n", + "\n", + "Let's install all the relevant dependencies required for inference." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:44:14.080155Z", + "iopub.status.busy": "2024-05-04T21:44:14.079850Z", + "iopub.status.idle": "2024-05-04T21:44:14.268405Z", + "shell.execute_reply": "2024-05-04T21:44:14.267431Z", + "shell.execute_reply.started": "2024-05-04T21:44:14.080123Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'2023.12.9'" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import tifffile\n", + "tifffile.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:44:19.450688Z", + "iopub.status.busy": "2024-05-04T21:44:19.450317Z", + "iopub.status.idle": "2024-05-04T21:44:50.915393Z", + "shell.execute_reply": "2024-05-04T21:44:50.913985Z", + "shell.execute_reply.started": "2024-05-04T21:44:19.450660Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Branch 'u-eval' set up to track remote branch 'u-eval' from 'origin'.\n", + "Switched to a new branch 'u-eval'\n" + ] + } + ], + "source": [ + "!git clone --quiet https://github.com/computational-cell-analytics/micro-sam.git\n", + "tmp_dir = os.path.join(root_dir, \"micro-sam\")\n", + "!pip install --quiet $tmp_dir" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:44:50.917830Z", + "iopub.status.busy": "2024-05-04T21:44:50.917466Z", + "iopub.status.idle": "2024-05-04T21:45:07.679259Z", + "shell.execute_reply": "2024-05-04T21:45:07.678080Z", + "shell.execute_reply.started": "2024-05-04T21:44:50.917796Z" + } + }, + "outputs": [], + "source": [ + "!git clone --quiet https://github.com/constantinpape/torch-em.git\n", + "tmp_dir = os.path.join(root_dir, \"torch-em\")\n", + "!pip install --quiet $tmp_dir" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:45:07.680930Z", + "iopub.status.busy": "2024-05-04T21:45:07.680657Z", + "iopub.status.idle": "2024-05-04T21:45:24.217947Z", + "shell.execute_reply": "2024-05-04T21:45:24.216679Z", + "shell.execute_reply.started": "2024-05-04T21:45:07.680903Z" + } + }, + "outputs": [], + "source": [ + "!git clone --quiet https://github.com/constantinpape/elf.git\n", + "tmp_dir = os.path.join(root_dir, \"elf\")\n", + "!pip install --quiet $tmp_dir" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:45:24.220872Z", + "iopub.status.busy": "2024-05-04T21:45:24.220548Z", + "iopub.status.idle": "2024-05-04T21:46:48.480726Z", + "shell.execute_reply": "2024-05-04T21:46:48.479468Z", + "shell.execute_reply.started": "2024-05-04T21:45:24.220841Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/497deca9.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/09cdf8bf.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/c6f2354e.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/86b0f08d.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/c9ddbd6b.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/b121c3e7.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/47929eba.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/3e39a7aa.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/2ce54b42.json\" was modified by another program\n", + "\u001b[33m\u001b[1mwarning libmamba\u001b[m Cache file \"/opt/conda/pkgs/cache/4ea078d6.json\" was modified by another program\n", + "Preparing transaction: ...working... done\n", + "Verifying transaction: ...working... done\n", + "Executing transaction: ...working... done\n" + ] + } + ], + "source": [ + "!mamba install -q -y -c conda-forge nifty affogato zarr z5py\n", + "!pip uninstall -y --quiet qtpy # qtpy is not supported in Kaggle / Google Colab, let's remove it to avoid errors." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Importing the libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:46:48.482513Z", + "iopub.status.busy": "2024-05-04T21:46:48.482210Z", + "iopub.status.idle": "2024-05-04T21:47:07.965841Z", + "shell.execute_reply": "2024-05-04T21:47:07.964844Z", + "shell.execute_reply.started": "2024-05-04T21:46:48.482484Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2024-05-04 21:46:57.737845: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n", + "2024-05-04 21:46:57.737940: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n", + "2024-05-04 21:46:57.859988: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n" + ] + } + ], + "source": [ + "from glob import glob\n", + "\n", + "import imageio.v3 as imageio\n", + "from matplotlib import pyplot as plt\n", + "\n", + "from torch_em.util.util import get_random_colors\n", + "\n", + "from micro_sam.util import get_sam_model\n", + "from micro_sam.evaluation import inference\n", + "from micro_sam.evaluation.model_comparison import _enhance_image\n", + "from micro_sam.sample_data import fetch_tracking_example_data, fetch_tracking_segmentation_data\n", + "from micro_sam.evaluation.evaluation import run_evaluation, run_evaluation_for_iterative_prompting" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Let's download the dataset" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:47:07.967379Z", + "iopub.status.busy": "2024-05-04T21:47:07.967088Z", + "iopub.status.idle": "2024-05-04T21:47:10.801916Z", + "shell.execute_reply": "2024-05-04T21:47:10.801162Z", + "shell.execute_reply.started": "2024-05-04T21:47:07.967355Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Downloading data from 'http://data.celltrackingchallenge.net/training-datasets/DIC-C2DH-HeLa.zip' to file '/kaggle/working/data/DIC-C2DH-HeLa.zip'.\n", + "100%|█████████████████████████████████████| 41.5M/41.5M [00:00<00:00, 49.0GB/s]\n", + "Extracting 'DIC-C2DH-HeLa/01/t000.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t001.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t002.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t003.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t004.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t005.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t006.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t007.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t008.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t009.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t010.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t011.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t012.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t013.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t014.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t015.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t016.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t017.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t018.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t019.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t020.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t021.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t022.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t023.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t024.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t025.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t026.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t027.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t028.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t029.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t030.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t031.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t032.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t033.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t034.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t035.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t036.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t037.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t038.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t039.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t040.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t041.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t042.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t043.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t044.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t045.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t046.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t047.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t048.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t049.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t050.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t051.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t052.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t053.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t054.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t055.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t056.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t057.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t058.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t059.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t060.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t061.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t062.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t063.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t064.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t065.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t066.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t067.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t068.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t069.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t070.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t071.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t072.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t073.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t074.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t075.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t076.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t077.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t078.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t079.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t080.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t081.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t082.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Extracting 'DIC-C2DH-HeLa/01/t083.tif' from '/kaggle/working/data/DIC-C2DH-HeLa.zip' to '/kaggle/working/data/DIC-C2DH-HeLa.zip.unzip'\n", + "Downloading data from 'https://owncloud.gwdg.de/index.php/s/AWxQMblxwR99OjC/download' to file '/kaggle/working/data/hela-ctc-01-gt.zip'.\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example data directory is: /kaggle/working/data\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|████████████████████████████████████████| 725k/725k [00:00<00:00, 962MB/s]\n", + "Extracting 'masks/mask_0000.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0001.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0002.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0003.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0004.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0005.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0006.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0007.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0008.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0009.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0010.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0011.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0012.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0013.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0014.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0015.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0016.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0017.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0018.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0019.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0020.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0021.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0022.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0023.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0024.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0025.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0026.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0027.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0028.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0029.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0030.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0031.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0032.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0033.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0034.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0035.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0036.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0037.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0038.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0039.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0040.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0041.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0042.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0043.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0044.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0045.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0046.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0047.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0048.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0049.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0050.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0051.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0052.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0053.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0054.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0055.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0056.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0057.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0058.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0059.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0060.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0061.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0062.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0063.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0064.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0065.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0066.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0067.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0068.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0069.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0070.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0071.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0072.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0073.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0074.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0075.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0076.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0077.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0078.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0079.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0080.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0081.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0082.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n", + "Extracting 'masks/mask_0083.tif' from '/kaggle/working/data/hela-ctc-01-gt.zip' to '/kaggle/working/data/hela-ctc-01-gt.zip.unzip'\n" + ] + } + ], + "source": [ + "DATA_FOLDER = os.path.join(root_dir, \"data\")\n", + "os.makedirs(DATA_FOLDER, exist_ok=True)\n", + "\n", + "# This will download the image and segmentation data for training.\n", + "image_dir = fetch_tracking_example_data(DATA_FOLDER)\n", + "segmentation_dir = fetch_tracking_segmentation_data(DATA_FOLDER)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Let's create our necessary functionality\n", + "\n", + "With reference to our suggestion for batched evaluation of the Segment Anything models (see our [documentation](https://github.com/computational-cell-analytics/micro-sam/tree/master/finetuning/evaluation#how-to-run-the-evaluation-scripts-on-your-own-data) for details) on our own data, the first step is to create a convenience function to wrap the input images and respective instance labels around a function." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:47:10.803785Z", + "iopub.status.busy": "2024-05-04T21:47:10.803396Z", + "iopub.status.idle": "2024-05-04T21:47:10.810494Z", + "shell.execute_reply": "2024-05-04T21:47:10.809484Z", + "shell.execute_reply.started": "2024-05-04T21:47:10.803752Z" + } + }, + "outputs": [], + "source": [ + "def get_paths(split=None):\n", + " \"\"\"For this dataset, we have a total of 84 images.\n", + " \n", + " We choose:\n", + " - The first 5 images as the validation images, for grid search (relevant for AMG ans AIS)\n", + " - The next 79 images as the test images, for running the inference(s).\n", + " \"\"\"\n", + " image_paths = sorted(glob(os.path.join(image_dir, \"*\")))\n", + " gt_paths = sorted(glob(os.path.join(segmentation_dir, \"*\")))\n", + " \n", + " if split is None:\n", + " return image_paths, gt_paths\n", + "\n", + " else:\n", + " if split == \"val\":\n", + " return image_paths[:1], gt_paths[:1]\n", + " elif split == \"test\":\n", + " return image_paths[5:], gt_paths[5:]\n", + " else:\n", + " raise ValueError(f\"'{split}' is not a valid split name.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Let's visualize how our samples look" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:47:10.812065Z", + "iopub.status.busy": "2024-05-04T21:47:10.811805Z", + "iopub.status.idle": "2024-05-04T21:47:10.852193Z", + "shell.execute_reply": "2024-05-04T21:47:10.851429Z", + "shell.execute_reply.started": "2024-05-04T21:47:10.812043Z" + } + }, + "outputs": [], + "source": [ + "# Convenience function to plot images side-by-side\n", + "def plot_samples(image, gt, segmentation=None):\n", + " n_images = 2 if segmentation is None else 3\n", + " fig, ax = plt.subplots(1, n_images, figsize=(10, 10))\n", + " \n", + " ax[0].imshow(_enhance_image(image, do_norm=False), cmap=\"gray\")\n", + " ax[0].axis(\"off\")\n", + " ax[0].set_title(\"Image\")\n", + " \n", + " ax[1].imshow(gt, cmap=get_random_colors(gt), interpolation=\"nearest\")\n", + " ax[1].axis(\"off\")\n", + " ax[1].set_title(\"Ground Truth\")\n", + " \n", + " if n_images == 3:\n", + " ax[2].imshow(segmentation, cmap=get_random_colors(segmentation), interpolation=\"nearest\")\n", + " ax[2].axis(\"off\")\n", + " ax[2].set_title(\"Prediction\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:47:10.853667Z", + "iopub.status.busy": "2024-05-04T21:47:10.853352Z" + } + }, + "outputs": [], + "source": [ + "image_paths, segmentation_paths = get_paths(split=\"test\")\n", + "\n", + "for image_path, segmentation_path in zip(image_paths, segmentation_paths):\n", + " image = imageio.imread(image_path)\n", + " segmentation = imageio.imread(segmentation_path)\n", + "\n", + " plot_samples(image=image, gt=segmentation)\n", + " \n", + " break # comment this out in case you want to visualize all the images" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "AMG" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:47:11.299652Z", + "iopub.status.busy": "2024-05-04T21:47:11.296914Z", + "iopub.status.idle": "2024-05-04T21:47:11.306466Z", + "shell.execute_reply": "2024-05-04T21:47:11.305694Z", + "shell.execute_reply.started": "2024-05-04T21:47:11.299603Z" + } + }, + "outputs": [], + "source": [ + "val_image_paths, val_gt_paths = get_paths(split=\"val\")\n", + "test_image_paths, test_gt_paths = get_paths(split=\"test\")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:47:11.308412Z", + "iopub.status.busy": "2024-05-04T21:47:11.307803Z", + "iopub.status.idle": "2024-05-04T21:47:11.315306Z", + "shell.execute_reply": "2024-05-04T21:47:11.314470Z", + "shell.execute_reply.started": "2024-05-04T21:47:11.308387Z" + } + }, + "outputs": [], + "source": [ + "checkpoint=None # overwrite in case you have custom checkpoints to load models from\n", + "model_type = \"vit_b\" # overwrite with your desired choice of model\n", + "experiment_folder = os.path.join(root_dir, \"experiment_dir\", \"DIC-C2DH-HeLa\", model_type)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "execution": { + "iopub.execute_input": "2024-05-04T21:47:11.316801Z", + "iopub.status.busy": "2024-05-04T21:47:11.316425Z", + "iopub.status.idle": "2024-05-04T22:07:37.501411Z", + "shell.execute_reply": "2024-05-04T22:07:37.500479Z", + "shell.execute_reply.started": "2024-05-04T21:47:11.316772Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Downloading file 'vit_b' from 'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth' to '/root/.cache/micro_sam/models'.\n", + "Run instance segmentation grid-search: 0%| | 0/1 [00:00