From c583097fbdb48bed42ced72d683c1c98c4b35398 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 31 May 2022 19:32:55 +0800 Subject: [PATCH 1/6] [DLMED] improve several cases Signed-off-by: Nic Ma --- docs/source/bundle.rst | 1 + docs/source/mb_specification.rst | 2 +- monai/transforms/croppad/array.py | 43 +++++++++++++++++-------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/docs/source/bundle.rst b/docs/source/bundle.rst index a28db04091..fc64d40f5a 100644 --- a/docs/source/bundle.rst +++ b/docs/source/bundle.rst @@ -41,3 +41,4 @@ Model Bundle .. autofunction:: run .. autofunction:: verify_metadata .. autofunction:: verify_net_in_out +.. autofunction:: init_bundle diff --git a/docs/source/mb_specification.rst b/docs/source/mb_specification.rst index a88096f274..61c4187f6b 100644 --- a/docs/source/mb_specification.rst +++ b/docs/source/mb_specification.rst @@ -104,7 +104,7 @@ The format for tensors used as inputs and outputs can be used to specify semanti * **latent**: ND tensor of data from the latent space from some layer of a network * **gradient**: ND tensor of gradients from some layer of a network -Spatial shape definition can be complex for models accepting inputs of varying shapes, especially if there are specific conditions on what those shapes can be. Shapes are specified as lists of either positive integers for fixed sizes or strings containing expressions defining the condition a size depends on. This can be "*" to mean any size, or use an expression with Python mathematical operators and one character variables to represent dependence on an unknown quantity. For example, "2**n" represents a size which must be a power of 2, "2**n*m" must be a multiple of a power of 2. Variables are shared between dimension expressions, so a spatial shape of `["2**n", "2**n"]` states that the dimensions must be the same powers of 2 given by `n`. +Spatial shape definition can be complex for models accepting inputs of varying shapes, especially if there are specific conditions on what those shapes can be. Shapes are specified as lists of either positive integers for fixed sizes or strings containing expressions defining the condition a size depends on. This can be "*" to mean any size, or use an expression with Python mathematical operators and one character variables to represent dependence on an unknown quantity. For example, "2**p" represents a size which must be a power of 2, "2**p*n" must be a multiple of a power of 2. Variables are shared between dimension expressions, a spatial shape example: `["*", "16*n", "2**p*n"]`. A JSON schema for this file can be found at https://github.com/Project-MONAI/MONAI/blob/3049e280f2424962bb2a69261389fcc0b98e0036/monai/apps/mmars/schema/metadata.json diff --git a/monai/transforms/croppad/array.py b/monai/transforms/croppad/array.py index 1245daa62c..cb31addae2 100644 --- a/monai/transforms/croppad/array.py +++ b/monai/transforms/croppad/array.py @@ -695,7 +695,7 @@ def __init__( return_coords: bool = False, k_divisible: Union[Sequence[int], int] = 1, mode: Optional[Union[NumpyPadMode, PytorchPadMode, str]] = NumpyPadMode.CONSTANT, - **np_kwargs, + **kwargs, ) -> None: """ Args: @@ -715,8 +715,8 @@ def __init__( One of the listed string values or a user supplied function. Defaults to ``"constant"``. See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html - np_kwargs: other args for `np.pad` API, note that `np.pad` treats channel dimension as the first dimension. - more details: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + kwargs: other arguments for the `np.pad` or `torch.pad` function. + note that `np.pad` treats channel dimension as the first dimension. """ self.select_fn = select_fn @@ -726,7 +726,7 @@ def __init__( self.return_coords = return_coords self.k_divisible = k_divisible self.mode: NumpyPadMode = look_up_option(mode, NumpyPadMode) - self.np_kwargs = np_kwargs + self.kwargs = kwargs def compute_bounding_box(self, img: NdarrayOrTensor): """ @@ -762,9 +762,9 @@ def crop_pad( pad_to_start = np.maximum(-box_start, 0) pad_to_end = np.maximum(box_end - np.asarray(img.shape[1:]), 0) pad = list(chain(*zip(pad_to_start.tolist(), pad_to_end.tolist()))) - return BorderPad(spatial_border=pad, mode=mode or self.mode, **self.np_kwargs)(cropped) + return BorderPad(spatial_border=pad, mode=mode or self.mode, **self.kwargs)(cropped) - def __call__(self, img: NdarrayOrTensor, mode: Optional[Union[NumpyPadMode, str]] = None): + def __call__(self, img: NdarrayOrTensor, mode: Optional[Union[NumpyPadMode, PytorchPadMode, str]] = None): """ Apply the transform to `img`, assuming `img` is channel-first and slicing doesn't change the channel dim. @@ -1139,14 +1139,16 @@ class ResizeWithPadOrCrop(Transform): Args: spatial_size: the spatial size of output data after padding or crop. If has non-positive values, the corresponding size of input image will be used (no padding). - mode: {``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, ``"mean"``, - ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} - One of the listed string values or a user supplied function for padding. Defaults to ``"constant"``. + mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, + ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} + available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}. + One of the listed string values or a user supplied function. Defaults to ``"constant"``. See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html method: {``"symmetric"``, ``"end"``} Pad image symmetrically on every side or only pad at the end sides. Defaults to ``"symmetric"``. - np_kwargs: other args for `np.pad` API, note that `np.pad` treats channel dimension as the first dimension. - more details: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + kwargs: other arguments for the `np.pad` or `torch.pad` function. + note that `np.pad` treats channel dimension as the first dimension. """ @@ -1155,23 +1157,26 @@ class ResizeWithPadOrCrop(Transform): def __init__( self, spatial_size: Union[Sequence[int], int], - mode: Union[NumpyPadMode, str] = NumpyPadMode.CONSTANT, + mode: Optional[Union[NumpyPadMode, PytorchPadMode, str]] = NumpyPadMode.CONSTANT, method: Union[Method, str] = Method.SYMMETRIC, - **np_kwargs, + **kwargs, ): - self.padder = SpatialPad(spatial_size=spatial_size, method=method, mode=mode, **np_kwargs) + self.padder = SpatialPad(spatial_size=spatial_size, method=method, mode=mode, **kwargs) self.cropper = CenterSpatialCrop(roi_size=spatial_size) - def __call__(self, img: NdarrayOrTensor, mode: Optional[Union[NumpyPadMode, str]] = None) -> NdarrayOrTensor: + def __call__( + self, img: NdarrayOrTensor, mode: Optional[Union[NumpyPadMode, PytorchPadMode, str]] = None + ) -> NdarrayOrTensor: """ Args: img: data to pad or crop, assuming `img` is channel-first and padding or cropping doesn't apply to the channel dim. - mode: {``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, ``"mean"``, - ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} - One of the listed string values or a user supplied function for padding. - If None, defaults to the ``mode`` in construction. + mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, + ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} + available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}. + One of the listed string values or a user supplied function. Defaults to ``"constant"``. See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html """ return self.padder(self.cropper(img), mode=mode) From 6da10451238f740e697f5578e73987a290f8f545 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 31 May 2022 19:48:20 +0800 Subject: [PATCH 2/6] [DLMED] update dict transform Signed-off-by: Nic Ma --- monai/transforms/croppad/dictionary.py | 33 +++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/monai/transforms/croppad/dictionary.py b/monai/transforms/croppad/dictionary.py index 57b257b428..f8fcb48fda 100644 --- a/monai/transforms/croppad/dictionary.py +++ b/monai/transforms/croppad/dictionary.py @@ -103,7 +103,6 @@ "RandCropByLabelClassesDict", ] -NumpyPadModeSequence = Union[Sequence[Union[NumpyPadMode, str]], NumpyPadMode, str] PadModeSequence = Union[Sequence[Union[NumpyPadMode, PytorchPadMode, str]], NumpyPadMode, PytorchPadMode, str] DEFAULT_POST_FIX = PostFix.meta() @@ -287,8 +286,8 @@ def __init__( ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}. One of the listed string values or a user supplied function. Defaults to ``"constant"``. - See also: https://numpy.org/doc/1.18/reference/ghttps://pytorch.orgenerated/numpy.pad.html - /docs/stable/generated/torch.nn.functional.pad.html + See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html It also can be a sequence of string, each element corresponds to a key in ``keys``. method: {``"symmetric"``, ``"end"``} Pad image symmetrically on every side or only pad at the end sides. Defaults to ``"symmetric"``. @@ -836,11 +835,11 @@ def __init__( margin: Union[Sequence[int], int] = 0, allow_smaller: bool = True, k_divisible: Union[Sequence[int], int] = 1, - mode: Optional[Union[NumpyPadMode, PytorchPadMode, str]] = NumpyPadMode.CONSTANT, + mode: PadModeSequence = NumpyPadMode.CONSTANT, start_coord_key: str = "foreground_start_coord", end_coord_key: str = "foreground_end_coord", allow_missing_keys: bool = False, - **np_kwargs, + **kwargs, ) -> None: """ Args: @@ -866,8 +865,8 @@ def __init__( start_coord_key: key to record the start coordinate of spatial bounding box for foreground. end_coord_key: key to record the end coordinate of spatial bounding box for foreground. allow_missing_keys: don't raise exception if key is missing. - np_kwargs: other args for `np.pad` API, note that `np.pad` treats channel dimension as the first dimension. - more details: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + kwargs: other arguments for the `np.pad` or `torch.pad` function. + note that `np.pad` treats channel dimension as the first dimension. """ super().__init__(keys, allow_missing_keys) @@ -880,7 +879,7 @@ def __init__( margin=margin, allow_smaller=allow_smaller, k_divisible=k_divisible, - **np_kwargs, + **kwargs, ) self.mode = ensure_tuple_rep(mode, len(self.keys)) @@ -1415,16 +1414,18 @@ class ResizeWithPadOrCropd(MapTransform, InvertibleTransform): See also: monai.transforms.MapTransform spatial_size: the spatial size of output data after padding or crop. If has non-positive values, the corresponding size of input image will be used (no padding). - mode: {``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, ``"mean"``, - ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} - One of the listed string values or a user supplied function for padding. Defaults to ``"constant"``. + mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``, + ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``} + available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}. + One of the listed string values or a user supplied function. Defaults to ``"constant"``. See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html It also can be a sequence of string, each element corresponds to a key in ``keys``. allow_missing_keys: don't raise exception if key is missing. method: {``"symmetric"``, ``"end"``} Pad image symmetrically on every side or only pad at the end sides. Defaults to ``"symmetric"``. - np_kwargs: other args for `np.pad` API, note that `np.pad` treats channel dimension as the first dimension. - more details: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + kwargs: other arguments for the `np.pad` or `torch.pad` function. + note that `np.pad` treats channel dimension as the first dimension. """ @@ -1434,14 +1435,14 @@ def __init__( self, keys: KeysCollection, spatial_size: Union[Sequence[int], int], - mode: NumpyPadModeSequence = NumpyPadMode.CONSTANT, + mode: PadModeSequence = NumpyPadMode.CONSTANT, allow_missing_keys: bool = False, method: Union[Method, str] = Method.SYMMETRIC, - **np_kwargs, + **kwargs, ) -> None: super().__init__(keys, allow_missing_keys) self.mode = ensure_tuple_rep(mode, len(self.keys)) - self.padcropper = ResizeWithPadOrCrop(spatial_size=spatial_size, method=method, **np_kwargs) + self.padcropper = ResizeWithPadOrCrop(spatial_size=spatial_size, method=method, **kwargs) def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> Dict[Hashable, NdarrayOrTensor]: d = dict(data) From 20c787606d0313cd951ea3444d4664e1524dd161 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 31 May 2022 19:53:53 +0800 Subject: [PATCH 3/6] [DLMED] update utils Signed-off-by: Nic Ma --- monai/data/utils.py | 11 ++++++----- monai/transforms/croppad/batch.py | 14 +++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/monai/data/utils.py b/monai/data/utils.py index bc4f60516d..93f96feae9 100644 --- a/monai/data/utils.py +++ b/monai/data/utils.py @@ -35,6 +35,7 @@ BlendMode, Method, NumpyPadMode, + PytorchPadMode, convert_data_type, convert_to_dst_type, ensure_tuple, @@ -557,8 +558,8 @@ def decollate_batch(batch, detach: bool = True, pad=True, fill_value=None): def pad_list_data_collate( batch: Sequence, method: Union[Method, str] = Method.SYMMETRIC, - mode: Union[NumpyPadMode, str] = NumpyPadMode.CONSTANT, - **np_kwargs, + mode: Union[NumpyPadMode, PytorchPadMode, str] = NumpyPadMode.CONSTANT, + **kwargs, ): """ Function version of :py:class:`monai.transforms.croppad.batch.PadListDataCollate`. @@ -576,13 +577,13 @@ def pad_list_data_collate( batch: batch of data to pad-collate method: padding method (see :py:class:`monai.transforms.SpatialPad`) mode: padding mode (see :py:class:`monai.transforms.SpatialPad`) - np_kwargs: other args for `np.pad` API, note that `np.pad` treats channel dimension as the first dimension. - more details: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + kwargs: other arguments for the `np.pad` or `torch.pad` function. + note that `np.pad` treats channel dimension as the first dimension. """ from monai.transforms.croppad.batch import PadListDataCollate # needs to be here to avoid circular import - return PadListDataCollate(method=method, mode=mode, **np_kwargs)(batch) + return PadListDataCollate(method=method, mode=mode, **kwargs)(batch) def no_collation(x): diff --git a/monai/transforms/croppad/batch.py b/monai/transforms/croppad/batch.py index 52d0c7be3b..ab16633fde 100644 --- a/monai/transforms/croppad/batch.py +++ b/monai/transforms/croppad/batch.py @@ -22,7 +22,7 @@ from monai.data.utils import list_data_collate from monai.transforms.croppad.array import CenterSpatialCrop, SpatialPad from monai.transforms.inverse import InvertibleTransform -from monai.utils.enums import Method, NumpyPadMode, TraceKeys +from monai.utils.enums import Method, NumpyPadMode, PytorchPadMode, TraceKeys __all__ = ["PadListDataCollate"] @@ -57,20 +57,20 @@ class PadListDataCollate(InvertibleTransform): Args: method: padding method (see :py:class:`monai.transforms.SpatialPad`) mode: padding mode (see :py:class:`monai.transforms.SpatialPad`) - np_kwargs: other args for `np.pad` API, note that `np.pad` treats channel dimension as the first dimension. - more details: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html + kwargs: other arguments for the `np.pad` or `torch.pad` function. + note that `np.pad` treats channel dimension as the first dimension. """ def __init__( self, method: Union[Method, str] = Method.SYMMETRIC, - mode: Union[NumpyPadMode, str] = NumpyPadMode.CONSTANT, - **np_kwargs, + mode: Union[NumpyPadMode, PytorchPadMode, str] = NumpyPadMode.CONSTANT, + **kwargs, ) -> None: self.method = method self.mode = mode - self.np_kwargs = np_kwargs + self.kwargs = kwargs def __call__(self, batch: Any): """ @@ -96,7 +96,7 @@ def __call__(self, batch: Any): continue # Use `SpatialPad` to match sizes, Default params are central padding, padding with 0's - padder = SpatialPad(spatial_size=max_shape, method=self.method, mode=self.mode, **self.np_kwargs) + padder = SpatialPad(spatial_size=max_shape, method=self.method, mode=self.mode, **self.kwargs) for idx, batch_i in enumerate(batch): orig_size = batch_i[key_or_idx].shape[1:] padded = padder(batch_i[key_or_idx]) From 466166567c4ceea6566ae327ca0f30534168afc6 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 31 May 2022 20:01:08 +0800 Subject: [PATCH 4/6] [DLMED] fix flake8 Signed-off-by: Nic Ma --- monai/transforms/croppad/array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/transforms/croppad/array.py b/monai/transforms/croppad/array.py index cb31addae2..b579471e1c 100644 --- a/monai/transforms/croppad/array.py +++ b/monai/transforms/croppad/array.py @@ -1157,7 +1157,7 @@ class ResizeWithPadOrCrop(Transform): def __init__( self, spatial_size: Union[Sequence[int], int], - mode: Optional[Union[NumpyPadMode, PytorchPadMode, str]] = NumpyPadMode.CONSTANT, + mode: Union[NumpyPadMode, PytorchPadMode, str] = NumpyPadMode.CONSTANT, method: Union[Method, str] = Method.SYMMETRIC, **kwargs, ): From a65c15bf59d195c0ee2e586e296a1588cf5cbda5 Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 31 May 2022 20:29:19 +0800 Subject: [PATCH 5/6] [DLMED] fix docs Signed-off-by: Nic Ma --- monai/bundle/__init__.py | 2 +- monai/transforms/croppad/array.py | 14 +++++++------- monai/transforms/croppad/dictionary.py | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/monai/bundle/__init__.py b/monai/bundle/__init__.py index 62e754e135..2a658a3c51 100644 --- a/monai/bundle/__init__.py +++ b/monai/bundle/__init__.py @@ -12,5 +12,5 @@ from .config_item import ComponentLocator, ConfigComponent, ConfigExpression, ConfigItem, Instantiable from .config_parser import ConfigParser from .reference_resolver import ReferenceResolver -from .scripts import ckpt_export, download, load, run, verify_metadata, verify_net_in_out +from .scripts import ckpt_export, download, init_bundle, load, run, verify_metadata, verify_net_in_out from .utils import EXPR_KEY, ID_REF_KEY, ID_SEP_KEY, MACRO_KEY, load_bundle_config diff --git a/monai/transforms/croppad/array.py b/monai/transforms/croppad/array.py index b579471e1c..6537cf3e21 100644 --- a/monai/transforms/croppad/array.py +++ b/monai/transforms/croppad/array.py @@ -695,7 +695,7 @@ def __init__( return_coords: bool = False, k_divisible: Union[Sequence[int], int] = 1, mode: Optional[Union[NumpyPadMode, PytorchPadMode, str]] = NumpyPadMode.CONSTANT, - **kwargs, + **pad_kwargs, ) -> None: """ Args: @@ -715,7 +715,7 @@ def __init__( One of the listed string values or a user supplied function. Defaults to ``"constant"``. See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html - kwargs: other arguments for the `np.pad` or `torch.pad` function. + pad_kwargs: other arguments for the `np.pad` or `torch.pad` function. note that `np.pad` treats channel dimension as the first dimension. """ @@ -726,7 +726,7 @@ def __init__( self.return_coords = return_coords self.k_divisible = k_divisible self.mode: NumpyPadMode = look_up_option(mode, NumpyPadMode) - self.kwargs = kwargs + self.pad_kwargs = pad_kwargs def compute_bounding_box(self, img: NdarrayOrTensor): """ @@ -762,7 +762,7 @@ def crop_pad( pad_to_start = np.maximum(-box_start, 0) pad_to_end = np.maximum(box_end - np.asarray(img.shape[1:]), 0) pad = list(chain(*zip(pad_to_start.tolist(), pad_to_end.tolist()))) - return BorderPad(spatial_border=pad, mode=mode or self.mode, **self.kwargs)(cropped) + return BorderPad(spatial_border=pad, mode=mode or self.mode, **self.pad_kwargs)(cropped) def __call__(self, img: NdarrayOrTensor, mode: Optional[Union[NumpyPadMode, PytorchPadMode, str]] = None): """ @@ -1147,7 +1147,7 @@ class ResizeWithPadOrCrop(Transform): https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html method: {``"symmetric"``, ``"end"``} Pad image symmetrically on every side or only pad at the end sides. Defaults to ``"symmetric"``. - kwargs: other arguments for the `np.pad` or `torch.pad` function. + pad_kwargs: other arguments for the `np.pad` or `torch.pad` function. note that `np.pad` treats channel dimension as the first dimension. """ @@ -1159,9 +1159,9 @@ def __init__( spatial_size: Union[Sequence[int], int], mode: Union[NumpyPadMode, PytorchPadMode, str] = NumpyPadMode.CONSTANT, method: Union[Method, str] = Method.SYMMETRIC, - **kwargs, + **pad_kwargs, ): - self.padder = SpatialPad(spatial_size=spatial_size, method=method, mode=mode, **kwargs) + self.padder = SpatialPad(spatial_size=spatial_size, method=method, mode=mode, **pad_kwargs) self.cropper = CenterSpatialCrop(roi_size=spatial_size) def __call__( diff --git a/monai/transforms/croppad/dictionary.py b/monai/transforms/croppad/dictionary.py index f8fcb48fda..50cc767cab 100644 --- a/monai/transforms/croppad/dictionary.py +++ b/monai/transforms/croppad/dictionary.py @@ -839,7 +839,7 @@ def __init__( start_coord_key: str = "foreground_start_coord", end_coord_key: str = "foreground_end_coord", allow_missing_keys: bool = False, - **kwargs, + **pad_kwargs, ) -> None: """ Args: @@ -865,7 +865,7 @@ def __init__( start_coord_key: key to record the start coordinate of spatial bounding box for foreground. end_coord_key: key to record the end coordinate of spatial bounding box for foreground. allow_missing_keys: don't raise exception if key is missing. - kwargs: other arguments for the `np.pad` or `torch.pad` function. + pad_kwargs: other arguments for the `np.pad` or `torch.pad` function. note that `np.pad` treats channel dimension as the first dimension. """ @@ -879,7 +879,7 @@ def __init__( margin=margin, allow_smaller=allow_smaller, k_divisible=k_divisible, - **kwargs, + **pad_kwargs, ) self.mode = ensure_tuple_rep(mode, len(self.keys)) @@ -1424,7 +1424,7 @@ class ResizeWithPadOrCropd(MapTransform, InvertibleTransform): allow_missing_keys: don't raise exception if key is missing. method: {``"symmetric"``, ``"end"``} Pad image symmetrically on every side or only pad at the end sides. Defaults to ``"symmetric"``. - kwargs: other arguments for the `np.pad` or `torch.pad` function. + pad_kwargs: other arguments for the `np.pad` or `torch.pad` function. note that `np.pad` treats channel dimension as the first dimension. """ @@ -1438,11 +1438,11 @@ def __init__( mode: PadModeSequence = NumpyPadMode.CONSTANT, allow_missing_keys: bool = False, method: Union[Method, str] = Method.SYMMETRIC, - **kwargs, + **pad_kwargs, ) -> None: super().__init__(keys, allow_missing_keys) self.mode = ensure_tuple_rep(mode, len(self.keys)) - self.padcropper = ResizeWithPadOrCrop(spatial_size=spatial_size, method=method, **kwargs) + self.padcropper = ResizeWithPadOrCrop(spatial_size=spatial_size, method=method, **pad_kwargs) def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> Dict[Hashable, NdarrayOrTensor]: d = dict(data) From 53b1dc19e0a9d939888a07f7e385a83b0ecd0b4f Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Tue, 31 May 2022 23:34:21 +0800 Subject: [PATCH 6/6] [DLMED] update according to comments Signed-off-by: Nic Ma --- docs/source/mb_specification.rst | 5 +++-- tests/testing_data/metadata.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/mb_specification.rst b/docs/source/mb_specification.rst index 61c4187f6b..142f250550 100644 --- a/docs/source/mb_specification.rst +++ b/docs/source/mb_specification.rst @@ -106,19 +106,20 @@ The format for tensors used as inputs and outputs can be used to specify semanti Spatial shape definition can be complex for models accepting inputs of varying shapes, especially if there are specific conditions on what those shapes can be. Shapes are specified as lists of either positive integers for fixed sizes or strings containing expressions defining the condition a size depends on. This can be "*" to mean any size, or use an expression with Python mathematical operators and one character variables to represent dependence on an unknown quantity. For example, "2**p" represents a size which must be a power of 2, "2**p*n" must be a multiple of a power of 2. Variables are shared between dimension expressions, a spatial shape example: `["*", "16*n", "2**p*n"]`. -A JSON schema for this file can be found at https://github.com/Project-MONAI/MONAI/blob/3049e280f2424962bb2a69261389fcc0b98e0036/monai/apps/mmars/schema/metadata.json +The download link of a JSON schema to verify this file can be found within it with key "schema". An example JSON metadata file: :: { + "schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json", "version": "0.1.0", "changelog": { "0.1.0": "complete the model package", "0.0.1": "initialize the model package structure" }, - "monai_version": "0.8.0", + "monai_version": "0.9.0", "pytorch_version": "1.10.0", "numpy_version": "1.21.2", "optional_packages_version": {"nibabel": "3.2.1"}, diff --git a/tests/testing_data/metadata.json b/tests/testing_data/metadata.json index c12ae411f1..98a17b73c5 100644 --- a/tests/testing_data/metadata.json +++ b/tests/testing_data/metadata.json @@ -5,7 +5,7 @@ "0.1.0": "complete the model package", "0.0.1": "initialize the model package structure" }, - "monai_version": "0.8.0", + "monai_version": "0.9.0", "pytorch_version": "1.10.0", "numpy_version": "1.21.2", "optional_packages_version": {