Skip to content

Commit 55074db

Browse files
Implement CLI WIP
1 parent d991be3 commit 55074db

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
license="MIT",
1414
entry_points={
1515
"console_scripts": [
16-
# TODO add segmentation CLI
16+
"synapse_net.run_segmentation = synaptic_reconstruction:tools.cli:segmentation_cli"
1717
],
1818
"napari.manifest": [
1919
"synaptic_reconstruction = synaptic_reconstruction:napari.yaml",

synaptic_reconstruction/tools/cli.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import argparse
2+
from functools import partial
3+
4+
from .util import run_segmentation
5+
from ..inference.util import inference_helper, parse_tiling
6+
7+
8+
def segmentation_cli():
9+
parser = argparse.ArgumentParser(description="Run segmentation.")
10+
parser.add_argument(
11+
"--input_path", "-i", required=True,
12+
help="The filepath to the mrc file or the directory containing the tomogram data."
13+
)
14+
parser.add_argument(
15+
"--output_path", "-o", required=True,
16+
help="The filepath to directory where the segmentations will be saved."
17+
)
18+
parser.add_argument(
19+
"--model_path", "-m", required=True, help="The filepath to the vesicle model."
20+
)
21+
parser.add_argument(
22+
"--mask_path", help="The filepath to a tif file with a mask that will be used to restrict the segmentation."
23+
"Can also be a directory with tifs if the filestructure matches input_path."
24+
)
25+
parser.add_argument("--input_key", "-k", required=False)
26+
parser.add_argument(
27+
"--force", action="store_true",
28+
help="Whether to over-write already present segmentation results."
29+
)
30+
parser.add_argument(
31+
"--tile_shape", type=int, nargs=3,
32+
help="The tile shape for prediction. Lower the tile shape if GPU memory is insufficient."
33+
)
34+
parser.add_argument(
35+
"--halo", type=int, nargs=3,
36+
help="The halo for prediction. Increase the halo to minimize boundary artifacts."
37+
)
38+
parser.add_argument(
39+
"--data_ext", default=".mrc", help="The extension of the tomogram data. By default .mrc."
40+
)
41+
args = parser.parse_args()
42+
43+
# TODO: preload the model!
44+
tiling = parse_tiling(args.tile_shape, args.halo)
45+
segmentation_function = partial(
46+
run_segmentation, model_path=args.model_path, verbose=False, tiling=tiling,
47+
)
48+
inference_helper(
49+
args.input_path, args.output_path, segmentation_function,
50+
mask_input_path=args.mask_path, force=args.force, data_ext=args.data_ext,
51+
)

0 commit comments

Comments
 (0)