Skip to content

Commit 58560e5

Browse files
committed
Merge remote-tracking branch 'origin/main' into v0.2
2 parents 5cb2ee6 + 07cd981 commit 58560e5

26 files changed

+165
-180
lines changed

.github/workflows/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
17-
- name: Set up Python 3.6
17+
- name: Set up Python 3.7
1818
uses: actions/setup-python@v2
1919
with:
20-
python-version: 3.6
20+
python-version: 3.7
2121
- name: Setup Dev Environment
2222
run: |
2323
pip install virtualenv

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sphinx:
1818

1919
# Optionally set the version of Python and requirements required to build your docs
2020
python:
21-
version: 3.6
21+
version: 3.7
2222
install:
2323
- requirements: docs/requirements.txt
2424
# system_packages: true

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
subprocess.call(
1818
"/bin/bash -c 'source /home/docs/checkouts/readthedocs.org/user_builds/"
19-
f"{READTHEDOCS_PROJECT}/envs/{READTHEDOCS_VERSION}/bin/activate; ../../run setup'",
19+
f"{READTHEDOCS_PROJECT}/envs/{READTHEDOCS_VERSION}/bin/activate; ../../run setup read_the_docs'",
2020
shell=True,
2121
)
2222
subprocess.call(

docs/source/getting_started/installing_app_sdk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
MONAI Deploy App SDK is available as a Python package through [Python Package Index (PyPI)](https://pypi.org/project/monai-deploy-app-sdk/).
44

5-
MONAI Deploy App SDK's core functionality is written in Python 3 (>= 3.6) for Linux.
5+
MONAI Deploy App SDK's core functionality is written in Python 3 (>= 3.7) for Linux.
66

77
```bash
88
pip install monai-deploy-app-sdk

docs/source/getting_started/tutorials/01_simple_app.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
## Setup
44

55
```bash
6-
# Create a virtual environment. Skip if you are already in a virtual environment.
7-
conda create -n monai python=3.6 pytorch torchvision jupyterlab cudatoolkit=11.1 -c pytorch -c conda-forge
6+
# Create a virtual environment with Python 3.7.
7+
# Skip if you are already in a virtual environment.
8+
# (JupyterLab dropped its support for Python 3.6 since 2021-12-23.
9+
# See https://github.com/jupyterlab/jupyterlab/pull/11740)
10+
conda create -n monai python=3.7 pytorch torchvision jupyterlab cudatoolkit=11.1 -c pytorch -c conda-forge
811
conda activate monai
912

1013
# Launch JupyterLab if you want to work on Jupyter Notebook

docs/source/getting_started/tutorials/02_mednist_app.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
## Setup
44

55
```bash
6-
# Create a virtual environment. Skip if you are already in a virtual environment.
7-
conda create -n mednist python=3.6 pytorch jupyterlab cudatoolkit=11.1 -c pytorch -c conda-forge
6+
# Create a virtual environment with Python 3.7.
7+
# Skip if you are already in a virtual environment.
8+
# (JupyterLab dropped its support for Python 3.6 since 2021-12-23.
9+
# See https://github.com/jupyterlab/jupyterlab/pull/11740)
10+
conda create -n mednist python=3.7 pytorch jupyterlab cudatoolkit=11.1 -c pytorch -c conda-forge
811
conda activate mednist
912

1013
# Launch JupyterLab if you want to work on Jupyter Notebook

docs/source/getting_started/tutorials/03_segmentation_app.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
## Setup
44

55
```bash
6-
# Create a virtual environment. Skip if you are already in a virtual environment.
7-
conda create -n monai python=3.6 pytorch torchvision jupyterlab cudatoolkit=11.1 -c pytorch -c conda-forge
6+
# Create a virtual environment with Python 3.7.
7+
# Skip if you are already in a virtual environment.
8+
# (JupyterLab dropped its support for Python 3.6 since 2021-12-23.
9+
# See https://github.com/jupyterlab/jupyterlab/pull/11740)
10+
conda create -n monai python=3.7 pytorch torchvision jupyterlab cudatoolkit=11.1 -c pytorch -c conda-forge
811
conda activate monai
912

1013
# Launch JupyterLab if you want to work on Jupyter Notebook
@@ -50,25 +53,25 @@ cd monai-deploy-app-sdk
5053
# Install monai-deploy-app-sdk package
5154
pip install monai-deploy-app-sdk
5255

53-
# Download/Extract ai_spleen_seg_data.zip from https://drive.google.com/file/d/1uTQsm8omwimBcp_kRXlduWBP2M6cspr1/view?usp=sharing
56+
# Download/Extract ai_spleen_seg_data zip file from https://drive.google.com/file/d/1GC_N8YQk_mOWN02oOzAU_2YDmNRWk--n/view?usp=sharing
5457

5558
# Download ai_spleen_seg_data.zip
5659
pip install gdown
57-
gdown https://drive.google.com/uc?id=1uTQsm8omwimBcp_kRXlduWBP2M6cspr1
60+
gdown https://drive.google.com/uc?id=1GC_N8YQk_mOWN02oOzAU_2YDmNRWk--n
5861

5962
# After downloading ai_spleen_seg_data.zip from the web browser or using gdown,
60-
unzip -o ai_spleen_seg_data.zip
63+
unzip -o ai_spleen_seg_data_updated_1203.zip
6164

6265
# Install necessary packages from the app
6366
pip install monai pydicom SimpleITK Pillow nibabel
6467

6568
# Local execution of the app
66-
python examples/apps/ai_spleen_seg_app/app.py -i dcm/ -o output -m model.pt
69+
python examples/apps/ai_spleen_seg_app/app.py -i dcm/ -o output -m model.ts
6770

6871
# Package app (creating MAP docker image) using `-l DEBUG` option to see progress.
6972
# This assumes that nvidia docker is installed in the local machine.
7073
# Please see https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker to install nvidia-docker2.
71-
monai-deploy package examples/apps/ai_spleen_seg_app --tag seg_app:latest --model model.pt -l DEBUG
74+
monai-deploy package examples/apps/ai_spleen_seg_app --tag seg_app:latest --model model.ts -l DEBUG
7275

7376
# Run the app with docker image and input file locally
7477
monai-deploy run seg_app:latest dcm/ output

docs/source/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
introduction/index
88
getting_started/index
99
developing_with_sdk/index
10+
```
11+
12+
```{toctree}
13+
:glob:
14+
:maxdepth: 2
15+
1016
modules/index
1117
```

docs/source/modules/index.md

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,14 @@
11
# MODULES APIS
22

3-
## Core
4-
53
```{toctree}
6-
:maxdepth: 3
7-
:hidden:
4+
:glob:
5+
:maxdepth: 2
86
97
core
10-
```
11-
12-
## Domain objects
13-
14-
```{toctree}
15-
:maxdepth: 2
16-
:hidden:
178
domain_objects
18-
```
19-
20-
## Operators
21-
22-
```{toctree}
23-
:maxdepth: 2
24-
:hidden:
259
operators
26-
```
27-
28-
## Models
29-
30-
```{toctree}
31-
:maxdepth: 2
32-
:hidden:
3310
models
34-
```
35-
36-
## Graphs
37-
38-
```{toctree}
39-
:maxdepth: 2
40-
:hidden:
4111
graphs
42-
```
43-
44-
## Executors
45-
46-
```{toctree}
47-
:maxdepth: 2
48-
:hidden:
4912
executors
50-
```
51-
52-
## Datastores
53-
54-
```{toctree}
55-
:maxdepth: 2
56-
:hidden:
5713
datastores
5814
```

docs/srs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ The SDK shall support the following system configurations for a given target rel
698698
| Docker CE | 19.03.13+ ([2020-09-16](https://docs.docker.com/engine/release-notes/19.03/#190313)) |
699699
| NVIDIA Docker | [v2.5.0+](https://github.com/NVIDIA/nvidia-docker/) |
700700
| CUDA Compute Capability | 6.0 or larger (Pascal or newer, including Pascal, Volta, Turing and Ampere families) |
701-
| Python | Python 3.6+ |
701+
| Python | Python 3.7+ |
702702

703703

704704
### System Config #2 (Desktop ARM64)
@@ -714,7 +714,7 @@ The SDK shall support the following system configurations for a given target rel
714714
| Docker CE | 19.03.13+ ([2020-09-16](https://docs.docker.com/engine/release-notes/19.03/#190313)) |
715715
| NVIDIA Docker | [v2.5.0+](https://github.com/NVIDIA/nvidia-docker/) |
716716
| CUDA Compute Capability | 6.0 or larger (Pascal or newer, including Pascal, Volta, Turing and Ampere families) |
717-
| Python | Python 3.6+ |
717+
| Python | Python 3.7+ |
718718

719719

720720
### System Config #3 (DGX-1)
@@ -730,4 +730,4 @@ The SDK shall support the following system configurations for a given target rel
730730
| Docker CE | 19.03.13+ ([2020-09-16](https://docs.docker.com/engine/release-notes/19.03/#190313)) |
731731
| NVIDIA Docker | [v2.5.0+](https://github.com/NVIDIA/nvidia-docker/) |
732732
| CUDA Compute Capability | 7.0 or larger (Volta or newer, including Volta, Turing and Ampere families) |
733-
| Python | Python 3.6+ |
733+
| Python | Python 3.7+ |

monai/deploy/cli/exec_command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
def create_exec_parser(subparser: _SubParsersAction, command: str, parents: List[ArgumentParser]) -> ArgumentParser:
2525
# Intentionally use `argparse.HelpFormatter` instead of `argparse.ArgumentDefaultsHelpFormatter`.
2626
# Default values for those options are None and those would be filled by `RuntimeEnv` object later.
27-
parser = subparser.add_parser(command, formatter_class=argparse.HelpFormatter, parents=parents, add_help=False)
27+
parser: ArgumentParser = subparser.add_parser(
28+
command, formatter_class=argparse.HelpFormatter, parents=parents, add_help=False
29+
)
2830

2931
parser.add_argument("--input", "-i", help="Path to input folder/file (default: input)")
3032
parser.add_argument("--output", "-o", help="Path to output folder (default: output)")

monai/deploy/core/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(
9595
self.path = get_class_file_path(self.__class__)
9696

9797
# Set the runtime environment
98-
if str(self.path).startswith("<ipython-"):
98+
if str(self.path) == "ipython":
9999
self.in_ipython = True
100100
else:
101101
self.in_ipython = False

monai/deploy/operators/dicom_series_to_volume_operator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,16 @@ def generate_voxel_data(self, series):
8484
# This is to have the same numpy ndarray as from Monai ImageReader (ITK, NiBabel etc).
8585
vol_data = np.stack([np.transpose(s.get_pixel_array()) for s in slices], axis=-1)
8686
vol_data = vol_data.astype(np.int16)
87-
intercept = slices[0][0x0028, 0x1052].value
88-
slope = slices[0][0x0028, 0x1053].value
87+
# Rescale Intercept and Slope attributes might be missing, but safe to assume defaults.
88+
try:
89+
intercept = slices[0][0x0028, 0x1052].value
90+
except KeyError:
91+
intercept = 0
92+
93+
try:
94+
slope = slices[0][0x0028, 0x1053].value
95+
except KeyError:
96+
slope = 1
8997

9098
if slope != 1:
9199
vol_data = slope * vol_data.astype(np.float64)

monai/deploy/operators/monai_seg_inference_operator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
np_str_obj_array_pattern, _ = optional_import("torch.utils.data._utils.collate", name="np_str_obj_array_pattern")
2121
Dataset, _ = optional_import("monai.data", name="Dataset")
2222
DataLoader, _ = optional_import("monai.data", name="DataLoader")
23-
ImageReader_, _ = optional_import("monai.data", name="ImageReader")
23+
ImageReader_, image_reader_ok_ = optional_import("monai.data", name="ImageReader")
2424
# Dynamic class is not handled so make it Any for now: https://github.com/python/mypy/issues/2477
2525
ImageReader: Any = ImageReader_
26+
if not image_reader_ok_:
27+
ImageReader = object # for 'class InMemImageReader(ImageReader):' to work
2628
decollate_batch, _ = optional_import("monai.data", name="decollate_batch")
2729
sliding_window_inference, _ = optional_import("monai.inferers", name="sliding_window_inference")
2830
ensure_tuple, _ = optional_import("monai.utils", name="ensure_tuple")

monai/deploy/packager/package_command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818

1919
def create_package_parser(subparser: _SubParsersAction, command: str, parents: List[ArgumentParser]) -> ArgumentParser:
20-
parser = subparser.add_parser(command, formatter_class=argparse.HelpFormatter, parents=parents, add_help=False)
20+
parser: ArgumentParser = subparser.add_parser(
21+
command, formatter_class=argparse.HelpFormatter, parents=parents, add_help=False
22+
)
2123

2224
parser.add_argument("application", type=str, help="MONAI application path")
2325
parser.add_argument(

monai/deploy/packager/templates.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,36 @@
1212
COMMON_FOOTPRINT = """
1313
USER root
1414
15-
RUN pip install --no-cache-dir --upgrade setuptools==57.4.0 pip==21.2.4 wheel==0.37.0
15+
RUN pip install --no-cache-dir --upgrade setuptools==57.4.0 pip==21.2.4 wheel==0.37.0 monai-deploy-app-sdk==0.2.0
1616
17-
RUN groupadd -g $MONAI_GID -o -r monai
18-
RUN useradd -g $MONAI_GID -u $MONAI_UID -m -o -r monai
19-
20-
RUN mkdir -p /etc/monai/ && chown -R monai:monai /etc/monai \\
21-
&& mkdir -p /opt/monai/ && chown -R monai:monai /opt/monai \\
22-
&& mkdir -p {working_dir} && chown -R monai:monai {working_dir} \\
23-
&& mkdir -p {app_dir} && chown -R monai:monai {app_dir} \\
24-
&& mkdir -p {executor_dir} && chown -R monai:monai {executor_dir} \\
25-
&& mkdir -p {full_input_path} && chown -R monai:monai {full_input_path} \\
26-
&& mkdir -p {full_output_path} && chown -R monai:monai {full_output_path} \\
27-
&& mkdir -p {models_dir} && chown -R monai:monai {models_dir}
17+
RUN mkdir -p /etc/monai/ \\
18+
&& mkdir -p /opt/monai/ \\
19+
&& mkdir -p {working_dir} \\
20+
&& mkdir -p {app_dir} \\
21+
&& mkdir -p {executor_dir} \\
22+
&& mkdir -p {full_input_path} \\
23+
&& mkdir -p {full_output_path} \\
24+
&& mkdir -p {models_dir}
2825
2926
{models_string}
3027
31-
COPY --chown=monai:monai ./pip/requirements.txt {map_requirements_path}
28+
COPY ./pip/requirements.txt {map_requirements_path}
3229
3330
RUN curl {executor_url} -o {executor_dir}/executor.zip \\
3431
&& unzip {executor_dir}/executor.zip -d {executor_dir}/executor_pkg \\
3532
&& mv {executor_dir}/executor_pkg/lib/native/linux-x64/* {executor_dir} \\
3633
&& rm -f {executor_dir}/executor.zip \\
3734
&& rm -rf {executor_dir}/executor_pkg \\
38-
&& chown -R monai:monai {executor_dir} \\
3935
&& chmod +x {executor_dir}/monai-exec
4036
41-
USER monai
42-
ENV PATH=/home/monai/.local/bin:$PATH
43-
44-
RUN pip install --no-cache-dir --upgrade -r {map_requirements_path}
45-
46-
# Override monai-deploy-app-sdk module
47-
COPY --chown=monai:monai ./monai-deploy-app-sdk /home/monai/.local/lib/python3.8/site-packages/monai/deploy/
37+
ENV PATH=/home/root/.local/bin:$PATH
4838
49-
COPY --chown=monai:monai ./map/app.json /etc/monai/
50-
COPY --chown=monai:monai ./map/pkg.json /etc/monai/
39+
RUN pip install --no-cache-dir -r {map_requirements_path}
5140
52-
COPY --chown=monai:monai ./app {app_dir}
41+
COPY ./map/app.json /etc/monai/
42+
COPY ./map/pkg.json /etc/monai/
5343
54-
# Create bytecodes for monai and app's code. This would help speed up loading time a little bit.
55-
RUN python -m compileall -q -j 0 /home/monai/.local/lib/python3.8/site-packages/monai /opt/monai/app
44+
COPY ./app {app_dir}
5645
5746
# Set the working directory
5847
WORKDIR {working_dir}
@@ -63,9 +52,6 @@
6352
UBUNTU_DOCKERFILE_TEMPLATE = (
6453
"""FROM {base_image}
6554
66-
ARG MONAI_GID=1000
67-
ARG MONAI_UID=1000
68-
6955
LABEL base="{base_image}"
7056
LABEL tag="{tag}"
7157
LABEL version="{app_version}"
@@ -100,9 +86,6 @@
10086
PYTORCH_DOCKERFILE_TEMPLATE = (
10187
"""FROM {base_image}
10288
103-
ARG MONAI_GID=1000
104-
ARG MONAI_UID=1000
105-
10689
LABEL base="{base_image}"
10790
LABEL tag="{tag}"
10891
LABEL version="{app_version}"

monai/deploy/packager/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def build_image(args: dict, temp_dir: str):
194194
else:
195195
shutil.copytree(model_path, dest_model_path)
196196

197-
models_string = f"RUN mkdir -p {models_dir} && chown -R monai:monai {models_dir}\n"
198-
models_string += f"COPY --chown=monai:monai ./models {models_dir}\n"
197+
models_string = f"RUN mkdir -p {models_dir}\n"
198+
models_string += f"COPY ./models {models_dir}\n"
199199

200200
# Dockerfile template
201201
template_params = {

monai/deploy/runner/run_command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121

2222
def create_run_parser(subparser: _SubParsersAction, command: str, parents: List[ArgumentParser]) -> ArgumentParser:
23-
parser = subparser.add_parser(command, formatter_class=HelpFormatter, parents=parents, add_help=False)
23+
parser: ArgumentParser = subparser.add_parser(
24+
command, formatter_class=HelpFormatter, parents=parents, add_help=False
25+
)
2426

2527
parser.add_argument("map", metavar="<map-image[:tag]>", help="MAP image name")
2628

0 commit comments

Comments
 (0)