About the Example MoNuSeg Dataset

from https://monuseg.grand-challenge.org: Training data containing 30 images and around 22,000 nuclear boundary annotations has been released to the public previously as a dataset article in IEEE Transactions on Medical imaging in 2017.

  • The train dataset (images and annotations) can be downloaded from https://drive. google.com/file/d/1ZgqFJomqQGNnsx7w7QBzQQMVA16lbVCA/view

How to download and preprocess the data can be found in the corresponding Notebook.

MonNuSegCover.png

Setup

In this section, you will set up the training environment, install all dependencies and connect to the drive with the prepared datasets.

!pip install -Uqq deepflash2
import numpy as np
from deepflash2.all import *
from pathlib import Path

Settings

Prior to training and predicting directorys need to be specified and parameters need to be set. For convenience exissting Google Drive folders can be used.

# Connect to drive
try:
  from google.colab import drive
  drive.mount('/gdrive')
except:
  print('Google Drive is not available.')

SEED = 0 # We used seeds [0,1,2] in our experiemnts
OUTPUT_PATH = Path("/content/predictions") # Save predictions here
MODEL_PATH = Path("/content/models") # Save models here
TRAINED_MODEL_PATH= Path('/gdrive/MyDrive/deepflash2-paper/models/')
DATA_PATH = Path('/gdrive/MyDrive/deepflash2-paper/data')

#################### Parameters ####################
DATASET = 'monuseg' 
mask_directory='masks_preprocessed'

# Datasets have different numbers of classes - 2 in case of monuseg
num_classes = 2
# Diameters are calculated using the median sizes from the respective training sets - 21 in case of monuseg
diameter = 21 

# Create deepflash2 config class
cfg = Config(random_state=SEED, 
            num_classes=num_classes, scale= 1.)
Drive already mounted at /gdrive; to attempt to forcibly remount, call drive.mount("/gdrive", force_remount=True).

Data preprocessing

  • Initialize EnsembleLearner
  • Plot images and masks to show if they are correctly loaded
train_data_path = DATA_PATH/DATASET/'train'
ensemble_path = MODEL_PATH/DATASET/f'{SEED+1}' 

el = EnsembleLearner(image_dir='images', 
                     mask_dir=mask_directory, 
                     config=cfg, 
                     path=train_data_path, 
                     ensemble_path=ensemble_path)

el.ds.show_data(max_n=2)
Found 37 images in "/gdrive/MyDrive/deepflash2-paper/data/monuseg/train/images".
Found 37 corresponding masks.
Preprocessing data
100.00% [37/37 00:37<00:00]
Calculated stats {'channel_means': array([164.25767168, 114.08958843, 153.99864962]), 'channel_stds': array([49.35636671, 50.20060809, 40.10077354]), 'max_tiles_per_image': 4}