From 8bd3ad8613041f29252dddbd937518ae1cbbfe16 Mon Sep 17 00:00:00 2001 From: monai-bot Date: Tue, 21 Mar 2023 09:37:42 +0000 Subject: [PATCH 1/5] [MONAI] code formatting Signed-off-by: monai-bot --- monai/apps/nnunet/__main__.py | 2 -- monai/apps/nnunet/utils.py | 1 - 2 files changed, 3 deletions(-) diff --git a/monai/apps/nnunet/__main__.py b/monai/apps/nnunet/__main__.py index 9e4ca5d073..14e2dca8d3 100644 --- a/monai/apps/nnunet/__main__.py +++ b/monai/apps/nnunet/__main__.py @@ -8,7 +8,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """ Examples: - User can use the one-liner to start the nnU-Net workflow @@ -85,7 +84,6 @@ """ - from __future__ import annotations from monai.apps.nnunet.nnunetv2_runner import nnUNetV2Runner diff --git a/monai/apps/nnunet/utils.py b/monai/apps/nnunet/utils.py index 773b9891c0..f49a9b76e9 100644 --- a/monai/apps/nnunet/utils.py +++ b/monai/apps/nnunet/utils.py @@ -25,7 +25,6 @@ logger = monai.apps.utils.get_logger(__name__) - __all__ = ["analyze_data", "create_new_data_copy", "create_new_dataset_json", "NNUNETMode"] From 6ef6873abff77fe683145649289c1ef3fe6ec278 Mon Sep 17 00:00:00 2001 From: Mingxin Zheng <18563433+mingxin-zheng@users.noreply.github.com> Date: Tue, 21 Mar 2023 09:39:16 +0000 Subject: [PATCH 2/5] Update ALGO_HASH to fix gpu_customization integration error (#6210) Fixes #6207 . ### Description A few sentences describing the changes proposed in this pull request. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [x] Integration tests passed locally by running the auto3dseg related integration tests. Signed-off-by: Mingxin Zheng <18563433+mingxin-zheng@users.noreply.github.com> --- monai/apps/auto3dseg/bundle_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/apps/auto3dseg/bundle_gen.py b/monai/apps/auto3dseg/bundle_gen.py index 462452007f..1831e9f840 100644 --- a/monai/apps/auto3dseg/bundle_gen.py +++ b/monai/apps/auto3dseg/bundle_gen.py @@ -35,7 +35,7 @@ from monai.utils import ensure_tuple logger = get_logger(module_name=__name__) -ALGO_HASH = os.environ.get("MONAI_ALGO_HASH", "d8bec42") +ALGO_HASH = os.environ.get("MONAI_ALGO_HASH", "4af80e1") __all__ = ["BundleAlgo", "BundleGen"] From 0ea3b851f987e7a64a1358d72b3eb4c9cbb3fc9d Mon Sep 17 00:00:00 2001 From: binliunls <107988372+binliunls@users.noreply.github.com> Date: Tue, 21 Mar 2023 17:47:50 +0800 Subject: [PATCH 3/5] 6208 fix-endoscopic-tool-segmentation-ckpt-export (#6209) Fixes #6208 . ### Description 1. Add `pre_conv` as a parameter to `FlexibleUNet` to make the model forward compatible. 2. Update the `torch.Tensor` type hint in the `UpCat` function to fit the torchscript requirement. ### Types of changes - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: binliu Signed-off-by: Wenqi Li Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Wenqi Li --- monai/networks/nets/basic_unet.py | 4 ++-- monai/networks/nets/flexible_unet.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/monai/networks/nets/basic_unet.py b/monai/networks/nets/basic_unet.py index b26fdcb622..c91335ccba 100644 --- a/monai/networks/nets/basic_unet.py +++ b/monai/networks/nets/basic_unet.py @@ -149,12 +149,12 @@ def __init__( self.convs = TwoConv(spatial_dims, cat_chns + up_chns, out_chns, act, norm, bias, dropout) self.is_pad = is_pad - def forward(self, x: torch.Tensor, x_e: torch.Tensor | None): + def forward(self, x: torch.Tensor, x_e: torch.Tensor): """ Args: x: features to be upsampled. - x_e: features from the encoder. + x_e: optional features from the encoder, if None, this branch is not in use. """ x_0 = self.upsample(x) diff --git a/monai/networks/nets/flexible_unet.py b/monai/networks/nets/flexible_unet.py index a880cafdc3..ac2124b5f9 100644 --- a/monai/networks/nets/flexible_unet.py +++ b/monai/networks/nets/flexible_unet.py @@ -232,6 +232,7 @@ def __init__( dropout: float | tuple = 0.0, decoder_bias: bool = False, upsample: str = "nontrainable", + pre_conv: str = "default", interp_mode: str = "nearest", is_pad: bool = True, ) -> None: @@ -262,6 +263,8 @@ def __init__( decoder_bias: whether to have a bias term in decoder's convolution blocks. upsample: upsampling mode, available options are``"deconv"``, ``"pixelshuffle"``, ``"nontrainable"``. + pre_conv:a conv block applied before upsampling. Only used in the "nontrainable" or + "pixelshuffle" mode, default to `default`. interp_mode: {``"nearest"``, ``"linear"``, ``"bilinear"``, ``"bicubic"``, ``"trilinear"``} Only used in the "nontrainable" mode. is_pad: whether to pad upsampling features to fit features from encoder. Default to True. @@ -309,7 +312,7 @@ def __init__( bias=decoder_bias, upsample=upsample, interp_mode=interp_mode, - pre_conv="default", + pre_conv=pre_conv, align_corners=None, is_pad=is_pad, ) From bcfab45a9915925c46dbf432e58d1d6eac8eea1e Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Tue, 21 Mar 2023 09:49:54 +0000 Subject: [PATCH 4/5] fixes https://github.com/Project-MONAI/MONAI/issues/6171 Signed-off-by: Wenqi Li --- monai/metrics/meandice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/metrics/meandice.py b/monai/metrics/meandice.py index 16eebdd28c..97a26f6a4e 100644 --- a/monai/metrics/meandice.py +++ b/monai/metrics/meandice.py @@ -205,7 +205,7 @@ def compute_channel(self, y_pred: torch.Tensor, y: torch.Tensor) -> torch.Tensor denorm = y_o + torch.sum(y_pred) if denorm <= 0: return torch.tensor(1.0, device=y_o.device) - return (2.0 * torch.sum(torch.masked_select(y, y_pred))) / denorm + return torch.tensor(0.0, device=y_o.device) def __call__(self, y_pred: torch.Tensor, y: torch.Tensor) -> torch.Tensor | tuple[torch.Tensor, torch.Tensor]: """ From c1a67844f58b8b68f69dbfc58b0faf5dffeb73d1 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Tue, 21 Mar 2023 10:09:13 +0000 Subject: [PATCH 5/5] fixes typing jit Signed-off-by: Wenqi Li --- monai/networks/nets/basic_unet.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/monai/networks/nets/basic_unet.py b/monai/networks/nets/basic_unet.py index c91335ccba..a29d620ced 100644 --- a/monai/networks/nets/basic_unet.py +++ b/monai/networks/nets/basic_unet.py @@ -12,6 +12,7 @@ from __future__ import annotations from collections.abc import Sequence +from typing import Any import torch import torch.nn as nn @@ -149,7 +150,7 @@ def __init__( self.convs = TwoConv(spatial_dims, cat_chns + up_chns, out_chns, act, norm, bias, dropout) self.is_pad = is_pad - def forward(self, x: torch.Tensor, x_e: torch.Tensor): + def forward(self, x: torch.Tensor, x_e: Any): """ Args: @@ -158,7 +159,7 @@ def forward(self, x: torch.Tensor, x_e: torch.Tensor): """ x_0 = self.upsample(x) - if x_e is not None: + if torch.jit.isinstance(x_e, torch.Tensor): if self.is_pad: # handling spatial shapes due to the 2x maxpooling with odd edge lengths. dimensions = len(x.shape) - 2