|
| 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