Skip to content

Commit 39adf31

Browse files
Release 0.1.0
* Update SGN model * Bump version * Update documentation
1 parent d993bc9 commit 39adf31

File tree

6 files changed

+47
-19
lines changed

6 files changed

+47
-19
lines changed

development/check_uploaded_models.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@
1818
}
1919

2020

21-
def check_segmentation_model(model_name, checkpoint_path=None):
21+
def check_segmentation_model(model_name, checkpoint_path=None, input_path=None, check_prediction=False, **kwargs):
2222
output_folder = f"result_{model_name}"
2323
os.makedirs(output_folder, exist_ok=True)
24-
input_path = os.path.join(output_folder, f"{model_name}.tif")
25-
if not os.path.exists(input_path):
26-
data_path = _sample_registry().fetch(data_dict[model_name])
27-
copyfile(data_path, input_path)
24+
if input_path is None:
25+
input_path = os.path.join(output_folder, f"{model_name}.tif")
26+
if not os.path.exists(input_path):
27+
data_path = _sample_registry().fetch(data_dict[model_name])
28+
copyfile(data_path, input_path)
2829

2930
output_path = os.path.join(output_folder, "segmentation.zarr")
3031
if not os.path.exists(output_path):
31-
cmd = ["flamingo_tools.run_segmentation", "-i", input_path, "-o", output_folder, "-m", model_name]
32+
cmd = [
33+
"flamingo_tools.run_segmentation", "-i", input_path, "-o", output_folder, "-m", model_name,
34+
"--disable_masking", "--min_size", "5",
35+
]
36+
for name, val in kwargs.items():
37+
cmd.extend([f"--{name}", str(val)])
3238
if checkpoint_path is not None:
3339
cmd.extend(["-c", checkpoint_path])
3440
subprocess.run(cmd)
@@ -38,6 +44,9 @@ def check_segmentation_model(model_name, checkpoint_path=None):
3844
image = imageio.imread(input_path)
3945
v = napari.Viewer()
4046
v.add_image(image)
47+
if check_prediction:
48+
prediction = zarr.open(os.path.join(output_folder, "predictions.zarr"))["prediction"][:]
49+
v.add_image(prediction)
4150
v.add_labels(segmentation, name=f"{model_name}-segmentation")
4251
napari.run()
4352

@@ -77,11 +86,13 @@ def main():
7786
# - Prediction works well on the GPU.
7887
# check_segmentation_model("IHC")
7988

80-
# TODO: Update model.
8189
# SGN segmentation (lowres):
82-
# - Prediction does not work well on the CPU.
83-
# - Prediction does not work well on the GPU.
84-
check_segmentation_model("SGN-lowres", checkpoint_path="SGN-lowres.pt")
90+
# - Prediction works well on the CPU.
91+
# - Prediction works well on the GPU.
92+
check_segmentation_model(
93+
"SGN-lowres",
94+
# boundary_distance_threshold=0.5, center_distance_threshold=None,
95+
)
8596

8697
# IHC segmentation (lowres):
8798
# - Prediction works well on the CPU.

development/export_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def export_synapses():
2121

2222

2323
def export_sgn_lowres():
24-
path = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/trained_models/SGN/cochlea_distance_unet_sgn-low-res-v4" # noqa
25-
model = load_model(path, device="cpu")
24+
path = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/trained_models/SGN/cochlea_distance_unet_sgn-low-res-v5" # noqa
25+
model = load_model(path, device="cpu", name="latest")
2626
torch.save(model, "SGN-lowres.pt")
2727

2828

doc/documentation.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,19 @@ Use `--file_ext .raw` if the data is stored in raw files. The the output data fo
8787
- If you specify `.n5` the data will be exported to the [bdv.n5 format](https://github.com/bigdataviewer/bigdataviewer-core/blob/master/BDV%20N5%20format.md). It can be opened with BigDataViewer via `Plugins->BigDataViewer->Open XML/HDF5` or with [BigStitcher](https://imagej.net/plugins/bigstitcher/) as described [here](https://imagej.net/plugins/bigstitcher/open-existing).
8888
- If you specify `.ome.zarr` the data will be exported to the [ome.zarr format](https://ngff.openmicroscopy.org/).
8989

90-
`flamingo_tools.run_segmentation`: To segment cells in volumetric light microscopy data.
90+
`flamingo_tools.run_segmentation`: To segment cells in volumetric light microscopy data. You can use this command as follows:
91+
```bash
92+
flamingo_tools.run_segmentation -i /path/to/data.tif -o /path/to/output_folder -m SGN
93+
```
94+
Here, `-m` determines which model is used. See also [available models](#available-models).
95+
To use a custom trained model you can use the argument `--checkpoint_path` (`-c`).
9196

92-
`flamingo_tools.run_detection`: To detect synapses in volumetric light microscopy data.
97+
`flamingo_tools.run_detection`: To detect synapses in volumetric light microscopy data. The command is used similarly to `flamingo_tools.run_segmentation`.
9398

9499
For more information on any of the command run `flamingo_tools.<COMMAND> -h` (e.g. `flamingo_tools.run_segmentation -h`) in your terminal.
95100

101+
We will add additional command line functionality soon.
102+
96103
### Python Library
97104

98105
CochleaNet's functionality is implemented in the `flamingo_tools` python library. It implements:

flamingo_tools/model_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ def get_model_registry() -> None:
6464
"SGN": "3058690b49015d6210a8e8414eb341c34189fee660b8fac438f1fdc41bdfff98",
6565
"IHC": "752dab7995b076ec4b8526b0539d1b33ade5de9251aaf6863d9bd8cc9cd036b6",
6666
"Synapses": "2a42712b056f082b4794f15cf41b15678aab0bec1acc922ff9f0dc76abe6747e",
67-
"SGN-lowres": "6accba4b4c65158fccf25623dcd0fb3b14203305d033a0d443a307114ec5dd8c",
67+
"SGN-lowres": "2c773792f0ef6022c7d052c452071cf7bf45dfce6b498b408ad6cd1cc3a30d35",
6868
"IHC-lowres": "537f1d4afc5a582771b87adeccadfa5635e1defd13636702363992188ef5bdbd",
6969
}
7070
urls = {
7171
"SGN": "https://owncloud.gwdg.de/index.php/s/NZ2vv7hxX1imITG/download",
7272
"IHC": "https://owncloud.gwdg.de/index.php/s/wB7d2MjV5LRTP06/download",
7373
"Synapses": "https://owncloud.gwdg.de/index.php/s/A9W5NmOeBxiyZgY/download",
74-
"SGN-lowres": "https://owncloud.gwdg.de/index.php/s/8hwZjBVzkuYhHLm/download",
74+
"SGN-lowres": "https://owncloud.gwdg.de/index.php/s/OS7985CKaTTBT5g/download",
7575
"IHC-lowres": "https://owncloud.gwdg.de/index.php/s/EhnV4brhpvFbSsy/download",
7676
}
7777
cache_dir = get_cache_dir()

flamingo_tools/segmentation/cli.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def _parse_kwargs(extra_kwargs, **default_kwargs):
1919
def _convert_argval(value):
2020
# The values for the parsed arguments need to be in the expected input structure as provided.
2121
# i.e. integers and floats should be in their original types.
22+
if value is None or value == "None":
23+
return None
2224
try:
2325
return int(value)
2426
except ValueError:
@@ -47,13 +49,21 @@ def _convert_argval(value):
4749

4850

4951
def _parse_segmentation_kwargs(extra_kwargs, model_type):
50-
if model_type.startswith("SGN"):
52+
if model_type == "SGN":
5153
default_kwargs = {
5254
"center_distance_threshold": 0.4,
5355
"boundary_distance_threshold": 0.5,
5456
"fg_threshold": 0.5,
5557
"distance_smoothing": 0.0,
56-
"seg_class": "sgn_low" if model_type == "SGN-lowres" else "sgn",
58+
"seg_class": "sgn",
59+
}
60+
elif model_type == "SGN-lowres":
61+
default_kwargs = {
62+
"center_distance_threshold": None,
63+
"boundary_distance_threshold": 0.5,
64+
"fg_threshold": 0.5,
65+
"distance_smoothing": 0.0,
66+
"seg_class": "sgn_low",
5767
}
5868
else:
5969
assert model_type.startswith("IHC")

flamingo_tools/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""@private
22
"""
33

4-
__version__ = "0.0.1"
4+
__version__ = "0.1.0"

0 commit comments

Comments
 (0)