Skip to content

Quick fix to avoid package not found error by use optional import #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions monai/deploy/operators/nii_data_loader_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
# limitations under the License.

import numpy as np
import SimpleITK

import monai.deploy.core as md
from monai.deploy.core import DataPath, ExecutionContext, InputContext, IOType, Operator, OutputContext
from monai.deploy.utils.importutil import optional_import

SimpleITK, _ = optional_import("SimpleITK")


@md.input("image_path", DataPath, IOType.DISK)
@md.output("image", np.ndarray, IOType.IN_MEMORY)
@md.env(pip_packages=["SimpleITK>=2.0.2"])
class NiftiDataLoader(Operator):
"""
This operator reads a nifti image, extracts the numpy array and forwards it to the next operator
Expand All @@ -42,7 +45,7 @@ def convert_and_save(self, nii_path):
def test():
filepath = "/home/gupta/Documents/mni_icbm152_nlin_sym_09a/mni_icbm152_gm_tal_nlin_sym_09a.nii"
nii_operator = NiftiDataLoader()
image_np = nii_operator.convert_and_save(filepath)
_ = nii_operator.convert_and_save(filepath)


def main():
Expand Down