Skip to content

Commit c85525a

Browse files
Merge pull request #516 from computational-cell-analytics/dev
Merge dev in preparation for new release
2 parents 3c2399d + e7fb2a8 commit c85525a

File tree

234 files changed

+19091
-3513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+19091
-3513
lines changed

.github/workflows/build_installers.yaml

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: build_installers
22

33
on:
4-
push:
5-
tags:
6-
- '**'
4+
workflow_dispatch:
75

86
jobs:
97
build_intaller:
@@ -13,15 +11,20 @@ jobs:
1311
strategy:
1412
fail-fast: false
1513
matrix:
16-
os: [windows-latest, ubuntu-latest, macos-latest]
14+
os: [windows-latest, ubuntu-latest] # macos-latest
1715

1816
env:
1917
PREPARE_SCRIPT: |
2018
cd deployment
21-
conda install -y -c conda-forge constructor
22-
conda install -y -c conda-forge ruamel.yaml
23-
conda install -y -c conda-forge mamba
24-
mamba env create --file=env.yaml
19+
mamba install -y -c conda-forge constructor
20+
mamba install -y -c conda-forge ruamel.yaml
21+
22+
mamba env create --file=../environment_cpu.yaml -n __MICROSAM_BUILD_ENV__
23+
mamba activate __MICROSAM_BUILD_ENV__
24+
# TODO get the current version here and use it for pinning or enable passing this from dispatch
25+
mamba install -c conda-forge micro_sam
26+
mamba activate base
27+
2528
RUN_SCRIPT: |
2629
python version_getter.py
2730
mkdir ./${{ matrix.os }}_x86_64
@@ -30,44 +33,47 @@ jobs:
3033
steps:
3134
- name: checkout
3235
uses: actions/checkout@v4
36+
with:
37+
ref: ${{ github.ref }}
3338

3439
- name: setup conda
35-
if: matrix.os == 'windows-latest' || matrix.os == 'ubuntu-latest'
40+
if: matrix.os == "windows-latest" || matrix.os == "ubuntu-latest"
3641
uses: conda-incubator/setup-miniconda@v2
3742
with:
3843
miniconda-version: "latest"
3944
auto-activate-base: true
4045
activate-environment: ""
46+
mamba-version: "*"
4147
env:
4248
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
4349

4450
- name: build ${{ matrix.os }}_x86_64
45-
if: matrix.os == 'windows-latest'
51+
if: matrix.os == "windows-latest"
4652
shell: pwsh
4753
run: |
4854
${{ env.PREPARE_SCRIPT }}
49-
conda activate __MICROSAM_BUILD_ENV__
50-
conda install -c anaconda menuinst
55+
mamba activate sam
56+
mamba install -c anaconda menuinst
5157
python windows_menu_setup.py
5258
conda activate base
5359
${{ env.RUN_SCRIPT }}
5460
5561
- name: build ${{ matrix.os }}_x86_64
56-
if: matrix.os == 'ubuntu-latest'
62+
if: matrix.os == "ubuntu-latest"
5763
shell: bash -el {0}
5864
run: |
5965
${{ env.PREPARE_SCRIPT }}
6066
${{ env.RUN_SCRIPT }}
6167
6268
- name: build ${{ matrix.os }}_x86_64_step1
63-
if: matrix.os == 'macos-latest'
69+
if: matrix.os == "macos-latest"
6470
shell: bash -el {0}
6571
run: |
6672
brew install micromamba
6773
/usr/local/opt/micromamba/bin/micromamba shell init -s bash -p ~/micromamba
6874
6975
- name: build ${{ matrix.os }}_x86_64_step2
70-
if: matrix.os == 'macos-latest'
76+
if: matrix.os == "macos-latest"
7177
shell: bash -el {0}
7278
run: |
7379
cd deployment

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,7 @@ cython_debug/
173173
# and can be added to the global gitignore or merged into this file. For a more nuclear
174174
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
175175
#.idea/
176+
177+
# Torch-em stuff
178+
checkpoints/
179+
logs/

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
[![codecov](https://codecov.io/gh/computational-cell-analytics/micro-sam/graph/badge.svg?token=7ETPP5CABP)](https://codecov.io/gh/computational-cell-analytics/micro-sam)
44
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7919746.svg)](https://doi.org/10.5281/zenodo.7919746)
55

6-
# SegmentAnything for Microscopy
6+
# Segment Anything for Microscopy
77

8-
Tools for segmentation and tracking in microscopy build on top of [SegmentAnything](https://segment-anything.com/).
8+
**Attention: We are currently updating our software to a new release that will improve it and introduce new features. The documentation is not up-to-date with these changes yet, we will update it as soon as possible!**
9+
10+
Tools for segmentation and tracking in microscopy build on top of [Segment Anything](https://segment-anything.com/).
911
Segment and track objects in microscopy images interactively with a few clicks!
1012

1113
We implement napari applications for:
@@ -22,21 +24,16 @@ If you run into any problems or have questions regarding our tool please open an
2224

2325
## Installation and Usage
2426

25-
You can install `micro_sam` via conda:
26-
```
27-
conda install -c conda-forge micro_sam napari pyqt
28-
```
29-
You can then start the `micro_sam` tools by running `$ micro_sam.annotator` in the command line.
27+
Please check [the documentation](https://computational-cell-analytics.github.io/micro-sam/) for details on how to install and use `micro_sam`. You can also find a quickstart guide in [this video](TODO) and find all video tutorials [here](https://www.youtube.com/watch?v=ket7bDUP9tI&list=PLwYZXQJ3f36GQPpKCrSbHjGiH39X4XjSO&pp=gAQBiAQB).
3028

31-
For an introduction in how to use the napari based annotation tools check out [the video tutorials](https://www.youtube.com/watch?v=ket7bDUP9tI&list=PLwYZXQJ3f36GQPpKCrSbHjGiH39X4XjSO&pp=gAQBiAQB).
32-
Please check out [the documentation](https://computational-cell-analytics.github.io/micro-sam/) for more details on the installation and usage of `micro_sam`.
3329

3430
## Contributing
3531

3632
We welcome new contributions!
3733

3834
If you are interested in contributing to micro-sam, please see the [contributing guide](doc/contributing.md) and [developer documentation](doc/development.md). The first step is to [discuss your idea in a new issue](https://github.com/computational-cell-analytics/micro-sam/issues/new) with the current developers.
3935

36+
4037
## Citation
4138

4239
If you are using this repository in your research please cite

deployment/construct.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
name: micro_sam
2-
version: 0.1.0
3-
license_file: ../LICENSE
4-
installer_type: pkg #[osx] # This will trigger pkg build on Mac Os. On windows and linux, native build will be done and this has no effect.
5-
environment: __MICROSAM_BUILD_ENV__
6-
welcome_image: ../doc/images/micro-sam-logo.png
7-
header_image: ../doc/images/micro-sam-logo.png
8-
icon_image: ../doc/images/micro-sam-logo.png
9-
channels:
10-
- conda-forge
11-
welcome_text: Install Segment Anything for Microscopy.
12-
conclusion_text: Segment Anything for Microscopy has been installed.
13-
initialize_by_default: false
1+
name: micro_sam
2+
version: 0.0.1
3+
license_file: ../LICENSE
4+
installer_type: pkg #[osx] # This will trigger pkg build on Mac Os. On windows and linux, native build will be done and this has no effect.
5+
environment: __MICROSAM_BUILD_ENV__
6+
welcome_image: ../doc/images/micro-sam-logo.png
7+
header_image: ../doc/images/micro-sam-logo.png
8+
icon_image: ../doc/images/micro-sam-logo.png
9+
channels:
10+
- conda-forge
11+
welcome_text: Install Segment Anything for Microscopy.
12+
conclusion_text: Segment Anything for Microscopy has been installed.
13+
initialize_by_default: false

deployment/version_getter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
yaml.preserve_quotes = True
77
ctor_fname = os.path.join("construct.yaml")
88

9-
with open(ctor_fname, 'r') as stream:
9+
with open(ctor_fname, "r") as stream:
1010
ctor_conf = yaml.load(stream)
1111

1212
ctor_conf["version"] = runpy.run_path(os.path.join("..", "micro_sam", "__version__.py"))["__version__"]
1313

14-
with open(ctor_fname, 'w') as outfile:
14+
with open(ctor_fname, "w") as outfile:
1515
yaml.dump(ctor_conf, outfile)

deployment/windows_menu.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"menu_items":
44
[
55
{
6-
"script": "${PREFIX}/Scripts/micro_sam.annotator.exe",
6+
"script": "${PREFIX}/Scripts/napari.exe",
77
"name": "micro_sam",
88
"icon": "${PREFIX}/Menu/micro-sam-logo.ico",
99
"workdir": "${PREFIX}",
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import os
2+
3+
import h5py
4+
from math import ceil
5+
6+
from micro_sam.sam_annotator import image_series_annotator, annotator_3d
7+
8+
9+
DATA_ROOT = "/home/anwai/data/lucchi/lucchi_test.h5"
10+
EMBEDDING_ROOT = "/home/anwai/embeddiings/test/"
11+
OUTPUT_ROOT = "/home/anwai/data/lucchi/outputs/"
12+
13+
14+
def _get_volume(volume_path):
15+
"""Getting the lucchi test volume"""
16+
with h5py.File(volume_path, "r") as f:
17+
raw = f["raw"][:]
18+
labels = f["labels"][:]
19+
20+
return raw, labels
21+
22+
23+
def segment_volume(input_volume, embedding_path):
24+
"""Load the entire volume in the tool for segmentation.
25+
"""
26+
assert input_volume.ndim == 3
27+
annotator_3d(
28+
image=input_volume,
29+
embedding_path=embedding_path,
30+
model_type="vit_b_em_organelles",
31+
tile_shape=None,
32+
halo=None,
33+
)
34+
35+
36+
def segment_each_slice(input_volume, embedding_dir, output_folder):
37+
"""Load each slice from the volume one-by-one in the tool for segmentation.
38+
"""
39+
assert input_volume.ndim == 3
40+
41+
all_slices = [each_slice for each_slice in input_volume]
42+
image_series_annotator(
43+
images=all_slices,
44+
output_folder=output_folder,
45+
model_type="vit_b_em_organelles",
46+
embedding_path=embedding_dir,
47+
tile_shape=None,
48+
halo=None,
49+
)
50+
51+
52+
def segment_each_n_slices(z_batch, input_volume, embedding_dir, output_folder):
53+
"""Load n slices from the volume one-by-one in the tool for segmentation.
54+
"""
55+
assert input_volume.ndim == 3
56+
57+
n_z_slices = input_volume.shape[0]
58+
all_z_idxx = int(ceil(n_z_slices / z_batch))
59+
60+
all_per_n_slices_volumes = []
61+
for z_id in range(all_z_idxx):
62+
z_start = z_id * z_batch
63+
z_stop = min((z_id + 1) * z_batch, n_z_slices)
64+
65+
batch_volume = input_volume[z_start: z_stop]
66+
all_per_n_slices_volumes.append(batch_volume)
67+
68+
print(f"We split the volume into {len(all_per_n_slices_volumes)} sub-volumes.")
69+
image_series_annotator(
70+
images=all_per_n_slices_volumes,
71+
output_folder=output_folder,
72+
model_type="vit_b_em_organelles",
73+
embedding_path=embedding_dir,
74+
tile_shape=None,
75+
halo=None,
76+
is_volumetric=True,
77+
)
78+
79+
80+
def main():
81+
raw, _ = _get_volume(DATA_ROOT)
82+
83+
# segment_volume(
84+
# input_volume=raw,
85+
# embedding_path=os.path.join(EMBEDDING_ROOT, "lucchi_3d_volume")
86+
# )
87+
88+
# segment_each_slice(
89+
# input_volume=raw,
90+
# embedding_dir=os.path.join(EMBEDDING_ROOT, "lucchi_2d_per_slice"),
91+
# output_folder=os.path.join(OUTPUT_ROOT, "per_slice_segmentation")
92+
# )
93+
94+
segment_each_n_slices(
95+
z_batch=15,
96+
input_volume=raw,
97+
embedding_dir=os.path.join(EMBEDDING_ROOT, "lucchi_3d_per_n_slices"),
98+
output_folder=os.path.join(OUTPUT_ROOT, "per_n_slices")
99+
)
100+
101+
102+
if __name__ == "__main__":
103+
main()

development/seg_with_decoder.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

doc/bioimageio/em_organelles_v2.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 light 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+
13+
## Validation
14+
15+
The easiest way to validate the model is to visually check the segmentation quality for your data.
16+
If you have annotations you can use for validation you can also quantitative validation, see [here for details](https://github.com/computational-cell-analytics/micro-sam/blob/master/doc/bioimageio/validation.md).
17+
Please note that the required quality for segmentation always depends on the analysis task you want to solve.

0 commit comments

Comments
 (0)