Skip to content

Commit c0afedb

Browse files
Update the cooper scripts
1 parent c75abd9 commit c0afedb

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

scripts/cooper/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ $ micromamba activate sam
1919
The segmentation scripts (`run_..._segmentation.py`) all work similarly and can either run segmentation for a single mrc file or for all mrcs in a folder structure.
2020
For example, you can run vesicle segmentation like this:
2121
```
22-
$ python run_vesicle_segmentation.py -i /path/to/input_folder -o /path/to/output_folder -m /path/to/vesicle_model.pt
22+
$ python run_vesicle_segmentation.py -i /path/to/input_folder -o /path/to/output_folder
2323
```
24-
The filepath after `-i` specifices the location of the folder with the mrcs to be segmented, the segmentation results will be stored (as tifs) in the folder following `-o` and `-m` is used to specify the path to the segmentation model.
24+
The filepath after `-i` specifices the location of the folder with the mrcs to be segmented and the segmentation results will be stored (as tifs) in the folder following `-o`.
2525
To segment vesicles with an additional mask, you can use the `--mask_path` option.
2626

2727
The segmentation scripts accept additional parameters, e.g. `--force` to overwrite existing segmentations in the output folder (by default these are skipped to avoid unnecessary computation) and `--tile_shape <TILE_Z> <TILE_Y> <TILE_X>` to specify a different tile shape (which may be necessary to avoid running out of GPU memory).

scripts/cooper/run_compartment_segmentation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
from functools import partial
33

44
from synapse_net.inference.compartments import segment_compartments
5+
from synapse_net.inference.inference import get_model_path
56
from synapse_net.inference.util import inference_helper, parse_tiling
67

78

89
def run_compartment_segmentation(args):
910
tiling = parse_tiling(args.tile_shape, args.halo)
11+
12+
if args.model is None:
13+
model_path = get_model_path("compartments")
14+
else:
15+
model_path = args.model
16+
1017
segmentation_function = partial(
11-
segment_compartments, model_path=args.model_path, verbose=False, tiling=tiling, scale=[0.25, 0.25, 0.25]
18+
segment_compartments, model_path=model_path, verbose=False, tiling=tiling, scale=[0.25, 0.25, 0.25]
1219
)
1320
inference_helper(
1421
args.input_path, args.output_path, segmentation_function, force=args.force, data_ext=args.data_ext
@@ -26,7 +33,7 @@ def main():
2633
help="The filepath to directory where the segmentation will be saved."
2734
)
2835
parser.add_argument(
29-
"--model_path", "-m", required=True, help="The filepath to the compartment model."
36+
"--model", "-m", help="The filepath to the compartment model."
3037
)
3138
parser.add_argument(
3239
"--force", action="store_true",

scripts/cooper/run_mitochondria_segmentation.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
from functools import partial
33

44
from synapse_net.inference.mitochondria import segment_mitochondria
5+
from synapse_net.inference.inference import get_model_path
56
from synapse_net.inference.util import inference_helper, parse_tiling
67

78

89
def run_mitochondria_segmentation(args):
10+
if args.model is None:
11+
model_path = get_model_path("mitochondria")
12+
else:
13+
model_path = args.model
14+
915
tiling = parse_tiling(args.tile_shape, args.halo)
1016
segmentation_function = partial(
11-
segment_mitochondria, model_path=args.model_path, verbose=False, tiling=tiling, scale=[0.5, 0.5, 0.5]
17+
segment_mitochondria, model_path=model_path, verbose=False, tiling=tiling, scale=[0.5, 0.5, 0.5]
1218
)
1319
inference_helper(
1420
args.input_path, args.output_path, segmentation_function,
@@ -27,7 +33,7 @@ def main():
2733
help="The filepath to directory where the segmentation will be saved."
2834
)
2935
parser.add_argument(
30-
"--model_path", "-m", required=True, help="The filepath to the mitochondria model."
36+
"--model", "-m", help="The filepath to the mitochondria model."
3137
)
3238
parser.add_argument(
3339
"--force", action="store_true",

scripts/cooper/run_vesicle_segmentation.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
from functools import partial
33

44
from synapse_net.inference.vesicles import segment_vesicles
5+
from synapse_net.inference.inference import get_model_path
56
from synapse_net.inference.util import inference_helper, parse_tiling
67

78

89
def run_vesicle_segmentation(args):
10+
if args.model is None:
11+
model_path = get_model_path("vesicles_3d")
12+
else:
13+
model_path = args.model
14+
915
tiling = parse_tiling(args.tile_shape, args.halo)
1016
segmentation_function = partial(
11-
segment_vesicles, model_path=args.model_path, verbose=False, tiling=tiling,
17+
segment_vesicles, model_path=model_path, verbose=False, tiling=tiling,
1218
exclude_boundary=not args.include_boundary
1319
)
1420
inference_helper(
@@ -28,7 +34,7 @@ def main():
2834
help="The filepath to directory where the segmentations will be saved."
2935
)
3036
parser.add_argument(
31-
"--model_path", "-m", required=True, help="The filepath to the vesicle model."
37+
"--model_path", "-m", help="The filepath to the vesicle model."
3238
)
3339
parser.add_argument(
3440
"--mask_path", help="The filepath to a tif file with a mask that will be used to restrict the segmentation."

0 commit comments

Comments
 (0)