Skip to content

Commit 3173303

Browse files
committed
Editorial changes to correct typos, rename parameters, adding comments. Retested examples.
Signed-off-by: M Q <[email protected]>
1 parent caf9790 commit 3173303

File tree

18 files changed

+74
-65
lines changed

18 files changed

+74
-65
lines changed

examples/apps/ai_unetr_seg_app/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def compose(self):
8080
_algorithm_family = codes.DCM.ArtificialIntelligence
8181
_algorithm_version = "0.1.0"
8282

83-
# List of (Segment name, [Code menaing str]), not including background which is value of 0.
83+
# List of (Segment name, [Code meaning str]), not including background which is value of 0.
8484
# User must provide correct codes, which can be looked at, e.g.
8585
# https://bioportal.bioontology.org/ontologies/SNOMEDCT
8686
# Alternatively, consult the concept and code dictionaries in PyDicom

examples/apps/ai_unetr_seg_app/unetr_seg_operator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class UnetrSegOperator(Operator):
5656

5757
def __init__(
5858
self,
59-
frament: Fragment,
59+
fragment: Fragment,
6060
*args,
6161
app_context: AppContext,
6262
model_path: Path,
@@ -71,13 +71,13 @@ def __init__(
7171
self.model_path = model_path
7272
self.output_folder = output_folder
7373
self.output_folder.mkdir(parents=True, exist_ok=True)
74-
self.fragement = frament # Cache and later pass the Fragment/Application to contained operator(s)
74+
self.app_fragment = fragment # Cache and later pass the Fragment/Application to contained operator(s)
7575
self.app_context = app_context
7676
self.input_name_image = "image"
7777
self.output_name_seg = "seg_image"
7878
self.output_name_saved_images_folder = "saved_images_folder"
7979

80-
super().__init__(frament, *args, **kwargs)
80+
super().__init__(fragment, *args, **kwargs)
8181

8282
def setup(self, spec: OperatorSpec):
8383
spec.input(self.input_name_image)
@@ -102,7 +102,7 @@ def compute(self, op_input, op_output, context):
102102

103103
# Delegates inference and saving output to the built-in operator.
104104
infer_operator = MonaiSegInferenceOperator(
105-
self.fragement,
105+
self.app_fragment,
106106
roi_size=(
107107
96,
108108
96,

examples/apps/breast_density_classifier_app/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Sample data and a torchscript model can be downloaded from https://drive.google.
99
python app.py -i <input_dir> -o <out_dir> -m <breast_density_model>
1010
```
1111

12-
## Package the application as a MONAI Application Package (contianer image)
12+
## Package the application as a MONAI Application Package (container image)
1313
In order to build the MONAI App Package, go a level up and execute the following command.
1414
```
1515
monai-deploy package breast_density_classification_app -m <breast_density_model> -c breast_density_classifer_app/app.yaml --tag breast_density:0.1.0 --platform x64-workstation -l DEBUG
@@ -20,4 +20,4 @@ monai-deploy package breast_density_classification_app -m <breast_density_model>
2020
monai-deploy run breast_density-x64-workstation-dgpu-linux-amd64:0.1.0 -i <input_dir> -o <output_dir>
2121
```
2222

23-
Once the container exits successfully, check the results in the output directory. There should be a newly creeated DICOM instance file and a `output.json` file containing the classification results.
23+
Once the container exits successfully, check the results in the output directory. There should be a newly created DICOM instance file and a `output.json` file containing the classification results.

examples/apps/breast_density_classifier_app/breast_density_classifier_operator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ClassifierOperator(Operator):
4040

4141
def __init__(
4242
self,
43-
frament: Fragment,
43+
fragment: Fragment,
4444
*args,
4545
model_name: Optional[str] = "",
4646
app_context: AppContext,
@@ -67,7 +67,7 @@ def __init__(
6767
# The name of the optional input port for passing data to override the output folder path.
6868
self.input_name_output_folder = "output_folder"
6969

70-
# The output folder set on the object can be overriden at each compute by data in the optional named input
70+
# The output folder set on the object can be overridden at each compute by data in the optional named input
7171
self.output_folder = output_folder
7272

7373
# Need the name when there are multiple models loaded
@@ -80,7 +80,7 @@ def __init__(
8080

8181
self.model = self._get_model(self.app_context, self.model_path, self._model_name)
8282

83-
super().__init__(frament, *args, **kwargs)
83+
super().__init__(fragment, *args, **kwargs)
8484

8585
def _get_model(self, app_context: AppContext, model_path: Path, model_name: str):
8686
"""Load the model with the given name from context or model path
@@ -116,7 +116,7 @@ def _convert_dicom_metadata_datatype(self, metadata: Dict):
116116
if not metadata:
117117
return metadata
118118

119-
# Try to convert data type for the well knowned attributes. Add more as needed.
119+
# Try to convert data type for the well known attributes. Add more as needed.
120120
if metadata.get("SeriesInstanceUID", None):
121121
try:
122122
metadata["SeriesInstanceUID"] = str(metadata["SeriesInstanceUID"])
Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
1-
import logging
1+
import argparse
2+
import logging
23
from pathlib import Path
3-
import torch
4+
5+
import numpy as np
6+
import torch
47
from diffusers import StableDiffusionPipeline
5-
from monai.deploy.core import AppContext, Application
68
from PIL import Image
7-
import numpy as np
8-
import argparse
99

10+
from monai.deploy.core import AppContext, Application
1011

1112

1213
class App(Application):
13-
name = "Diffusion Image App"
14-
description = "Simple application showing diffusion to generate Images"
15-
def compose(self):
16-
model_id = "Nihirc/Prompt2MedImage"
17-
device = "cuda"
18-
parser = argparse.ArgumentParser()
19-
parser.add_argument("--input_prompt", type=str, default="Generate a X-ray")
20-
parser.add_argument("--output", type=str, default="./out.jpg")
21-
args = parser.parse_args()
22-
23-
input_prompt = args.input_prompt
24-
output_path = args.output
25-
print("Input Prompt: ", input_prompt)
26-
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
27-
pipe = pipe.to(device)
28-
prompt = "Show me an X ray pevic fracture"
29-
image = pipe(prompt).images[0]
30-
image.save(output_path)
14+
name = "Diffusion Image App"
15+
description = "Simple application showing diffusion to generate Images"
16+
17+
def compose(self):
18+
model_id = "Nihirc/Prompt2MedImage"
19+
device = "cuda"
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument("--input_prompt", type=str, default="Generate a X-ray")
22+
parser.add_argument("--output", type=str, default="./out.jpg")
23+
args = parser.parse_args()
24+
25+
input_prompt = args.input_prompt
26+
output_path = args.output
27+
print("Input Prompt: ", input_prompt)
28+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
29+
pipe = pipe.to(device)
30+
prompt = "Show me an X ray pevic fracture"
31+
image = pipe(prompt).images[0]
32+
image.save(output_path)
3133

3234

3335
if __name__ == "__main__":
34-
logging.info(f"Begin {__name__}")
35-
App().run()
36-
logging.info(f"End {__name__}")
37-
38-
39-
36+
logging.info(f"Begin {__name__}")
37+
App().run()
38+
logging.info(f"End {__name__}")

examples/apps/mednist_classifier_monaideploy/mednist_classifier_monaideploy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class MedNISTClassifierOperator(Operator):
100100

101101
def __init__(
102102
self,
103-
frament: Fragment,
103+
fragment: Fragment,
104104
*args,
105105
app_context: AppContext,
106106
model_name: Optional[str] = "",
@@ -127,7 +127,7 @@ def __init__(
127127
# The name of the optional input port for passing data to override the output folder path.
128128
self.input_name_output_folder = "output_folder"
129129

130-
# The output folder set on the object can be overriden at each compute by data in the optional named input
130+
# The output folder set on the object can be overridden at each compute by data in the optional named input
131131
self.output_folder = output_folder
132132

133133
# Need the name when there are multiple models loaded
@@ -138,7 +138,7 @@ def __init__(
138138
self.model = self._get_model(self.app_context, self.model_path, self._model_name)
139139

140140
# This needs to be at the end of the constructor.
141-
super().__init__(frament, *args, **kwargs)
141+
super().__init__(fragment, *args, **kwargs)
142142

143143
def _get_model(self, app_context: AppContext, model_path: Path, model_name: str):
144144
"""Load the model with the given name from context or model path

examples/apps/simple_imaging_app/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
307307
# TAG-NUM-gHEX
308308
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
309309
if not mo:
310-
# unparseable. Maybe git-describe is misbehaving?
310+
# unparsable. Maybe git-describe is misbehaving?
311311
pieces["error"] = ("unable to parse git-describe output: '%s'"
312312
% describe_out)
313313
return pieces

examples/apps/simple_imaging_app/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def compose(self):
4949
output_data_path = Path(app_context.output_path)
5050
logging.info(f"sample_data_path: {sample_data_path}")
5151

52-
# Please note that the Application object, self, is passed as the first positonal argument
52+
# Please note that the Application object, self, is passed as the first positional argument
5353
# and the others as kwargs.
5454
# Also note the CountCondition of 1 on the first operator, indicating to the application executor
55-
# to invoke this operator, hence the pipleline, only once.
55+
# to invoke this operator, hence the pipeline, only once.
5656
sobel_op = SobelOperator(self, CountCondition(self, 1), input_path=sample_data_path, name="sobel_op")
5757
median_op = MedianOperator(self, name="median_op")
5858
gaussian_op = GaussianOperator(self, output_folder=output_data_path, name="gaussian_op")

examples/apps/simple_imaging_app/gaussian_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GaussianOperator(Operator):
2424
single input:
2525
an image array object
2626
single output:
27-
an image arrary object, without enforcing a downsteam receiver
27+
an image array object, without enforcing a downstream receiver
2828
2929
Besides, this operator also saves the image file in the given output folder.
3030
"""

monai/deploy/operators/clara_viz_operator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ClaraVizOperator(Operator):
3333
seg_image: Image object of the segmentation image derived from the input image.
3434
"""
3535

36-
def __init__(self, fragement: Fragment, *args, **kwargs):
36+
def __init__(self, fragment: Fragment, *args, **kwargs):
3737
"""Constructor of the operator.
3838
3939
Args:
@@ -43,7 +43,7 @@ def __init__(self, fragement: Fragment, *args, **kwargs):
4343
self.input_name_image = "image"
4444
self.input_name_seg_image = "seg_image"
4545

46-
super().__init__(fragement, *args, **kwargs)
46+
super().__init__(fragment, *args, **kwargs)
4747

4848
def setup(self, spec: OperatorSpec):
4949
spec.input(self.input_name_image)

0 commit comments

Comments
 (0)