Skip to content

Commit

Permalink
Move parser to own module and bump to 1.2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolphpienaar committed Apr 28, 2024
1 parent cbaf0f1 commit 4eb3214
Showing 1 changed file with 11 additions and 155 deletions.
166 changes: 11 additions & 155 deletions spleenseg/spleenseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import warnings
from pyfiglet import Figlet

from chris_plugin import chris_plugin

warnings.filterwarnings(
"ignore",
message="For details about installing the optional dependencies, please visit:",
)

from chris_plugin import chris_plugin, PathMapper

__version__ = "1.2.10"

DISPLAY_TITLE = r"""
Expand All @@ -42,160 +41,14 @@
╚══════╝╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝ ╚═══╝╚══════╝╚══════╝ ╚═════╝
"""

__version__ = "1.2.12"
import spleenseg.splparser as spl

parser = ArgumentParser(
description="""
description: str = """
A ChRIS DS plugin based on Project MONAI 3D Spleen Segmentation.
This plugin implements both training and inference, with some
refactoring and pervasive type hinting.
""",
formatter_class=ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--man",
default=False,
action="store_true",
help="If specified, print a manual page",
)
parser.add_argument(
"--mode",
type=str,
default="training",
help="mode of behaviour: training or inference",
)
parser.add_argument(
"--logTransformVols",
default=False,
action="store_true",
help="If specified, save intermediary and inference data as NIfTI volumes",
)
parser.add_argument(
"--useModel",
type=str,
default="model.pth",
help="model to use for inference processing",
)
parser.add_argument(
"--trainImageDir",
type=str,
default="imagesTr",
help="name of directory containing training images",
)
parser.add_argument(
"--trainLabelsDir",
type=str,
default="labelsTr",
help="name of directory containing training labels",
)
parser.add_argument(
"--testImageDir",
type=str,
default="imagesTs",
help="name of directory containing test data",
)
parser.add_argument(
"--device",
type=str,
default="cpu",
help="GPU/CPU device to use",
)
parser.add_argument(
"--determinismSeed",
type=int,
default=42,
help="the determinism seed for training/evaluation",
)
parser.add_argument(
"--maxEpochs",
type=int,
default=600,
help="max number of epochs to consider",
)
parser.add_argument(
"--validateSize",
type=int,
default=9,
help="size of the validation set in the input raw/label space",
)
parser.add_argument(
"--pattern", type=str, default="**/[!._]*nii.gz", help="filter glob for input files"
)
parser.add_argument(
"-V", "--version", action="version", version=f"%(prog)s {__version__}"
)


def manPage_print() -> None:
print(DISPLAY_TITLE)
print(
"""
NAME
spleenseg
SYNOPSIS
spleenseg --mode <inference|training> \\
[--man] \\
[--version] \\
[--logTransformVols] \\
[--useModel <modelFile>] \\
[--trainImageDir <train> --trainLabelsDir <label>] \\
[--testImageDir <dir>] \\
[--device <device>] \\
[--determinismSeed <seed>] \\
[--maxEpochs <count>] \\
[--validateSize <size>]
DESCRIPTION
"spleenseg" is a stand-alone app/ChRIS-plugin that can perform the training
and inference modes on detecting the spleen from abdominal images. It is based
on the project MONAI `spleen_segmentation` notebook exemplar. This app represents
a complete rewrite of the notebook code to allow for more functionality, telemetry
and re-usability.
ARGS
--mode <inference|training>
The mode of operation. If the "training" text has any additional characters,
then the epoch training is skipped and only the post-training logic is executed.
[--man]
If specified, print this help page and quit.
[--version]
If specified, print the version and quit.
[--logTransformVols]
If specified, log a set of intermediary NIfTI volumes as used for training,
validation, spacing, and inference.
[--useModel <modelFile>]
If specified, use <modelFile> for inference or continued training.
[--trainImageDir <train> --trainLabelsDir <label>]
In the <inputDir>, the name of the directory containing files for training
with their corresponding label targets.
[--testImageDir]
In the <inputDir> the name of the directory containing images for inference.
[--device <device>]
The device to use, typically "cpu" or "cuda:0".
[--determinismSeed <seed>]
Set the training seed.
[--maxEpochs <count>]
The max number of training epochs.
[--validateSize <size>]
In the training space, the number of images that should be used for validation
and not training.
"""
)
"""


def trainingData_prep(options: Namespace) -> list[dict[str, str]]:
Expand Down Expand Up @@ -249,7 +102,7 @@ def envDetail_print(options: Namespace, **kwargs):
Custom version of print_config() that suppresses the optional dependencies message.
"""
if options.man:
manPage_print()
spl.manPage_print()
sys.exit(1)
print(DISPLAY_TITLE)
f = Figlet(font="doom")
Expand Down Expand Up @@ -313,8 +166,11 @@ def inference_do(neuralNet: neuralnet.NeuralNet, options: Namespace) -> bool:
return inferenceOK


sparser = spl.parser_setup(description)


@chris_plugin(
parser=parser,
parser=sparser,
title="Spleen 3D image segmentation (MONAI)",
category="", # ref. https://chrisstore.co/plugins
min_memory_limit="16Gi", # supported units: Mi, Gi
Expand Down

0 comments on commit 4eb3214

Please sign in to comment.