Skip to content

Commit 63f9c00

Browse files
Merge pull request #1064 from computational-cell-analytics/dev
Prepare new release
2 parents 3ec97ab + 537ca97 commit 63f9c00

File tree

19 files changed

+399
-228
lines changed

19 files changed

+399
-228
lines changed

doc/band.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
# Using `micro_sam` on BAND
22

3-
BAND is a service offered by EMBL Heidelberg that gives access to a virtual desktop for image analysis tasks. It is free to use and `micro_sam` is installed there.
3+
BAND is a service offered by EMBL Heidelberg under the "The German Network for Bioinformatics Infrastructure" (de.NBI) that gives access to a virtual desktop for image analysis tasks. It is free to use and `micro_sam` is installed there.
44
In order to use BAND and start `micro_sam` on it follow these steps:
55

66
## Start BAND
7-
- Go to https://band.embl.de/ and click **Login**. If you have not used BAND before you will need to register for BAND. Currently you can only sign up via a Google account.
7+
- Go to https://bandv1.denbi.uni-tuebingen.de/ and click **Login**. If you have not used BAND before you will need to register for BAND. Currently you can only sign up via a Google account. NOTE: It takes a couple of seconds for the "Launch Desktops" window to appear.
88
- Launch a BAND desktop with sufficient resources. It's particularly important to select a GPU. The settings from the image below are a good choice.
99
- Go to the desktop by clicking **GO TO DESKTOP** in the **Running Desktops** menu. See also the screenshot below.
1010

11-
![image](https://github.com/computational-cell-analytics/micro-sam/assets/4263537/f965fce2-b924-4fc8-871b-f3201e502138)
11+
![image](https://github.com/user-attachments/assets/2e615769-b176-4ced-9507-99553aafb1c1)
1212

1313
## Start `micro_sam` in BAND
14-
- Select **Applications -> Image Analysis -> uSAM** (see screenshot)
15-
![image](https://github.com/computational-cell-analytics/micro-sam/assets/4263537/5daeafb3-119b-4104-8708-aab2960cb21c)
16-
- This will open the micro_sam menu, where you can select the tool you want to use (see screenshot). Note: this may take a few minutes.
17-
![image](https://github.com/computational-cell-analytics/micro-sam/assets/4263537/900ce0b9-4cf8-418c-94f1-e99ac7bc0086)
18-
- For testing if the tool works, it's best to use the **2d annotator** first.
19-
- You can find an example image to use here: `/scratch/cajal-connectomics/hela-2d-image.png`. Select it via **Select image**. (see screenshot)
20-
![image](https://github.com/computational-cell-analytics/micro-sam/assets/4263537/5fbd1c53-2ba1-47d4-ae50-dfab890ac9d3)
21-
- Then press **2d annotator** and the tool will start.
14+
- Select **Applications -> Image Analysis -> microSAM** (see screenshot)
15+
![image](https://github.com/user-attachments/assets/f1e7af0d-5cc6-442d-95c7-9010f5996e2a)
16+
17+
- This will open the napari GUI, where you can select the images and annotator tools you want to use (see screenshot). NOTE: this may take a few minutes.
18+
![image](https://github.com/user-attachments/assets/23296589-be8d-4f9f-9a38-92d5eea60541)
19+
20+
- For testing if the tool works, it's best to use the **Annotator 2d** first.
21+
- You can find an example image to use by selection `File` -> `Open Sample` -> `Segment Anything for Microscopy` -> `HeLa 2d example data` (see screenshot)
22+
![image](https://github.com/user-attachments/assets/ac259787-6238-4b68-8739-48a62f169913)
23+
- Then select `Plugins` -> `Segment Anything for Microscopy` -> `Annotator 2d`, and the tool will start.
24+
![image](https://github.com/user-attachments/assets/3062e723-6fe0-48f7-835f-663be7d78b87)
2225

2326
## Transfering data to BAND
2427

doc/bioimageio/em_organelles_v4.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Segment Anything for Electron Microscopy
2+
3+
This is a [Segment Anything](https://segment-anything.com/) model that was specialized for segmenting mitochondria and nuclei in electron microscopy with [micro_sam](https://github.com/computational-cell-analytics/micro-sam).
4+
This model uses a %s vision transformer as image encoder.
5+
6+
Segment Anything is a model for interactive and automatic instance segmentation.
7+
We improve it for electron microscopy by finetuning on a large and diverse microscopy dataset.
8+
It should perform well for segmenting mitochondria and nuclei in electron microscopy. It can also work well for other organelles, but was not explicitly trained for this purpose. You may get better results for other organelles (e.g. ER or Golgi) with the default Segment Anything models.
9+
10+
See [the dataset overview](https://github.com/computational-cell-analytics/micro-sam/blob/master/doc/datasets/em_organelles_v%i.md) for further informations on the training data and the [micro_sam documentation](https://computational-cell-analytics.github.io/micro-sam/micro_sam.html) for details on how to use the model for interactive and automatic segmentation.
11+
12+
NOTE: The model's automatic instance segmentation quality has improved as the latest version updates the segmentation decoder architecture by replacing transposed convolutions with upsampling.
13+
14+
15+
## Validation
16+
17+
The easiest way to validate the model is to visually check the segmentation quality for your data.
18+
If you have annotations you can use for validation you can also quantitative validation, see [here for details](https://computational-cell-analytics.github.io/micro-sam/micro_sam.html#9-how-can-i-evaluate-a-model-i-have-finetuned).
19+
Please note that the required quality for segmentation always depends on the analysis task you want to solve.

doc/bioimageio/lm_v4.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Segment Anything for Light Microscopy
2+
3+
This is a [Segment Anything](https://segment-anything.com/) model that was specialized for light microscopy with [micro_sam](https://github.com/computational-cell-analytics/micro-sam).
4+
This model uses a %s vision transformer as image encoder.
5+
6+
Segment Anything is a model for interactive and automatic instance segmentation.
7+
We improve it for light microscopy by finetuning on a large and diverse microscopy dataset.
8+
It should perform well for cell and nucleus segmentation in fluorescent, label-free and other light microscopy datasets.
9+
10+
See [the dataset overview](https://github.com/computational-cell-analytics/micro-sam/blob/master/doc/datasets/lm_v%i.md) for further informations on the training data and the [micro_sam documentation](https://computational-cell-analytics.github.io/micro-sam/micro_sam.html) for details on how to use the model for interactive and automatic segmentation.
11+
12+
NOTE: The model's automatic instance segmentation quality has improved as the latest version updates the segmentation decoder architecture by replacing transposed convolutions with upsampling.
13+
14+
15+
## Validation
16+
17+
The easiest way to validate the model is to visually check the segmentation quality for your data.
18+
If you have annotations you can use for validation you can also quantitative validation, see [here for details](https://computational-cell-analytics.github.io/micro-sam/micro_sam.html#9-how-can-i-evaluate-a-model-i-have-finetuned).
19+
Please note that the required quality for segmentation always depends on the analysis task you want to solve.

doc/datasets/em_organelles_v4.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Electron Microscopy Datasets
2+
3+
The `EM Organelle v4` model was trained on three different electron microscopy datasets with segmentation annotations for mitochondria and nuclei:
4+
5+
1. [MitoEM](https://mitoem.grand-challenge.org/): containing segmentation annotations for mitochondria in volume EM of human and rat cortex.
6+
2. [MitoLab](https://www.ebi.ac.uk/empiar/EMPIAR-11037/): containing segmentation annotations for mitochondria in different EM modalities.
7+
3. [Platynereis (Nuclei)](https://zenodo.org/records/3675220): contining segmentation annotations for nuclei in a blockface EM volume of *P. dumerilii*.

doc/datasets/lm_v4.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Light Microscopy Datasets
2+
3+
The `LM Generalist v4` model was trained on 14 different light microscopy datasets with segmentation annotations for cells and nuclei:
4+
5+
1. [LIVECell](https://sartorius-research.github.io/LIVECell/): containing cell segmentation annotations for phase-contrast microscopy.
6+
2. [DeepBacs](https://github.com/HenriquesLab/DeepBacs): containing segmentation annotations for bacterial cells in different label-free microscopy modalities.
7+
3. [TissueNet](https://datasets.deepcell.org/): containing cell segmentation annotations in tissues imaged with fluorescence light microscopy.
8+
4. [PlantSeg (Root)](https://osf.io/2rszy/): containing cell segmentation annotations in plant roots imaged with fluorescence lightsheet microscopy.
9+
5. [NeurIPS CellSeg](https://neurips22-cellseg.grand-challenge.org/): containg cell segmentation annotations in phase-contrast, brightfield, DIC and fluorescence microscopy.
10+
6. [CTC (Cell Tracking Challenge)](https://celltrackingchallenge.net/2d-datasets/): containing cell segmentation annotations in different label-free and fluorescence microscopy settings. We make use of the following CTC datasets: `BF-C2DL-HSC`, `BF-C2DL-MuSC`, `DIC-C2DH-HeLa`, `Fluo-C2DL-Huh7`, `Fluo-C2DL-MSC`, `Fluo-N2DH-SIM+`, `PhC-C2DH-U373`, `PhC-C2DL-PSC"`]
11+
7. [DSB Nucleus Segmentation](https://www.kaggle.com/c/data-science-bowl-2018): containing nucleus segmentation annotations in fluorescence microscopy. We make use of [this subset](https://github.com/stardist/stardist/releases/download/0.1.0/dsb2018.zip) of the data.
12+
8. [EmbedSeg](https://github.com/juglab/EmbedSeg): containing cell and nuclei annotations in fluorescence microcsopy.
13+
9. [YeaZ](https://www.epfl.ch/labs/lpbs/data-and-software): containing segmentation annotations for yeast cells in phase contrast and brightfield microscopy.
14+
10. [CVZ Fluo](https://www.synapse.org/Synapse:syn27624812/): containing cell and nuclei annotations in fluorescence microsocopy.
15+
11. [DynamicNuclearNet](https://datasets.deepcell.org/): containing nuclei annotations in fluorescence microscopy.
16+
12. [CellPose](https://www.cellpose.org/): containing cell annotations in fluorescence microscopy.
17+
13. [OmniPose](https://osf.io/xmury/): containing segmentation annotations for bacterial cells in phase-contrast and fluorescence microscopy, and worms in brightfield microscopy.
18+
14. [OrgaSegment](https://zenodo.org/records/10278229): containing segmentation annotations for organoids in brightfield microscopy.

finetuning/generalists/training/electron_microscopy/mito_nuc/obtain_mito_nuc_em_datasets.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def _check_dataset_available_for_rois(path, patch_shape):
3030
We do this only for "platynereis - nuclei", "mitoem" datasets - as we expect specific RoIs only from them
3131
"""
3232
datasets.get_mitoem_dataset(
33-
path=os.path.join(path, "mitoem"), patch_shape=patch_shape, download=True, splits="train"
33+
path=os.path.join(path, "mitoem"), patch_shape=patch_shape, download=True, splits="train",
3434
)
3535
datasets.get_platynereis_nuclei_dataset(
36-
path=os.path.join(path, "platynereis"), patch_shape=patch_shape, download=True
36+
path=os.path.join(path, "platynereis"), patch_shape=patch_shape, download=True,
3737
)
3838
print("All the datasets are available for RoI splitting")
3939

@@ -43,42 +43,49 @@ def get_concat_mito_nuc_datasets(input_path, patch_shape):
4343

4444
sampler = MinInstanceSampler()
4545
standard_label_trafo = PerObjectDistanceTransform(
46-
distances=True, boundary_distances=True, directed_distances=False, foreground=True, instances=True, min_size=0
46+
distances=True, boundary_distances=True, directed_distances=False, foreground=True, instances=True, min_size=0,
4747
)
4848

49-
# mitoem parameters
49+
# MitoEM dataset: ROI values.
5050
mitoem_train_rois = [np.s_[100:110, :, :], np.s_[100:110, :, :]]
5151
mitoem_val_rois = [np.s_[0:5, :, :], np.s_[0:5, :, :]]
5252

53-
# platynereis nuclei dataset parameters
53+
# Platynereis (Nuclei) dataset: ROI values.
5454
platy_root = os.path.join(input_path, "platynereis")
5555
platy_nuclei_template = "nuclei/train_data_nuclei_%02i.h5"
5656
platy_nuclei_label_key = "volumes/labels/nucleus_instance_labels"
5757

5858
platy_nuclei_train_samples = [1, 2, 3, 4, 5, 6, 7, 8]
59-
platy_nuclei_train_rois = compute_platy_rois(platy_root, platy_nuclei_train_samples, ignore_label=-1,
60-
file_template=platy_nuclei_template, label_key=platy_nuclei_label_key)
59+
platy_nuclei_train_rois = compute_platy_rois(
60+
platy_root, platy_nuclei_train_samples, ignore_label=-1,
61+
file_template=platy_nuclei_template, label_key=platy_nuclei_label_key,
62+
)
63+
6164
platy_nuclei_val_samples = [9, 10]
62-
platy_nuclei_val_rois = compute_platy_rois(platy_root, platy_nuclei_val_samples, ignore_label=-1,
63-
file_template=platy_nuclei_template, label_key=platy_nuclei_label_key)
65+
platy_nuclei_val_rois = compute_platy_rois(
66+
platy_root, platy_nuclei_val_samples, ignore_label=-1,
67+
file_template=platy_nuclei_template, label_key=platy_nuclei_label_key,
68+
)
6469

6570
def mitoem_dataset(split, roi_choice):
6671
return datasets.get_mitoem_dataset(
6772
path=os.path.join(input_path, "mitoem"), splits=split, download=True, patch_shape=patch_shape,
6873
rois=roi_choice, label_transform=standard_label_trafo, ndim=2, raw_transform=identity,
69-
sampler=MinInstanceSampler(min_num_instances=5)
74+
sampler=MinInstanceSampler(min_num_instances=4),
7075
)
7176

77+
# Get MitoEM dataset: mitochondria segmentation in vEM images.
7278
mitoem_train_dataset = mitoem_dataset("train", mitoem_train_rois)
7379
mitoem_val_dataset = mitoem_dataset("val", mitoem_val_rois)
7480

7581
def platy_nuclei_dataset(roi_choice, sample_ids):
7682
return datasets.get_platynereis_nuclei_dataset(
7783
path=platy_root, patch_shape=patch_shape, download=True, sampler=sampler, ndim=2,
7884
label_transform=ResizeLabelTrafo(patch_shape[1:]), rois=roi_choice,
79-
raw_transform=ResizeRawTrafo(patch_shape[1:], do_rescaling=False), sample_ids=sample_ids
85+
raw_transform=ResizeRawTrafo(patch_shape[1:], do_rescaling=False, ensure_rgb=False), sample_ids=sample_ids
8086
)
8187

88+
# Get Platynereis (Nuclei) dataset: nuclei segmentation in vEM images.
8289
platy_nuclei_train_dataset = platy_nuclei_dataset(platy_nuclei_train_rois, sample_ids=platy_nuclei_train_samples)
8390
platy_nuclei_val_dataset = platy_nuclei_dataset(platy_nuclei_val_rois, sample_ids=platy_nuclei_val_samples)
8491

@@ -87,10 +94,11 @@ def cem_dataset(split):
8794
n_samples = 1620 if split == "train" else 600
8895
return datasets.cem.get_mitolab_dataset(
8996
path=os.path.join(input_path, "mitolab"), split=split, val_fraction=0.1, sampler=sampler,
90-
raw_transform=ResizeRawTrafo(patch_shape[1:], do_rescaling=False), patch_shape=patch_shape[1:],
91-
label_transform=ResizeLabelTrafo(patch_shape[1:]), n_samples=n_samples
97+
raw_transform=ResizeRawTrafo(patch_shape[1:], do_rescaling=False, ensure_rgb=False),
98+
patch_shape=patch_shape[1:], label_transform=ResizeLabelTrafo(patch_shape[1:]), n_samples=n_samples,
9299
)
93100

101+
# Get CEM dataset: mitochondria segmentation in vEM images.
94102
cem_train_dataset = cem_dataset("train")
95103
cem_val_dataset = cem_dataset("val")
96104

@@ -111,14 +119,19 @@ def cem_dataset(split):
111119

112120
def get_generalist_mito_nuc_loaders(input_path, patch_shape):
113121
"""This returns the concatenated electron microscopy datasets implemented in torch_em:
114-
https://github.com/constantinpape/torch-em/tree/main/torch_em/data/datasets
122+
https://github.com/constantinpape/torch-em/tree/main/torch_em/data/datasets/electron_microscopy
115123
It will automatically download all the datasets
124+
116125
NOTE: to remove / replace the datasets with another dataset, you need to add the datasets (for train and val splits)
117126
in `get_concat_lm_dataset`. The labels have to be in a label mask instance segmentation format.
118127
i.e. the tensors (inputs & masks) should be of same spatial shape, with each object in the mask having it's own ID.
119128
IMPORTANT: the ID 0 is reserved for background, and the IDs must be consecutive.
120129
"""
130+
# Get the datasets.
121131
generalist_train_dataset, generalist_val_dataset = get_concat_mito_nuc_datasets(input_path, patch_shape)
132+
133+
# Get the dataloaders.
122134
train_loader = get_data_loader(generalist_train_dataset, batch_size=2, shuffle=True, num_workers=16)
123135
val_loader = get_data_loader(generalist_val_dataset, batch_size=1, shuffle=True, num_workers=16)
136+
124137
return train_loader, val_loader

0 commit comments

Comments
 (0)