Skip to content
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

5971-fix the pixelshuffle upsample shape mismatch problem. #5982

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ repos:
exclude: |
(?x)^(
monai/__init__.py|
docs/source/conf.py
docs/source/conf.py|
tests/utils.py
)$

- repo: https://github.com/hadialqattan/pycln
Expand Down
2 changes: 1 addition & 1 deletion monai/networks/nets/flexible_unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def __init__(
bias=decoder_bias,
upsample=upsample,
interp_mode=interp_mode,
pre_conv=None,
pre_conv="default",
align_corners=None,
is_pad=is_pad,
)
Expand Down
37 changes: 20 additions & 17 deletions tests/test_flexible_unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,32 @@ def make_shape_cases(
num_classes=10,
input_shape=64,
norm=("batch", {"eps": 1e-3, "momentum": 0.01}),
upsample=("nontrainable", "deconv", "pixelshuffle"),
):
ret_tests = []
for spatial_dim in spatial_dims: # selected spatial_dims
for batch in batches: # check single batch as well as multiple batch input
for model in models: # selected models
for is_pretrained in pretrained: # pretrained or not pretrained
if ("resnet" in model) and is_pretrained:
continue
kwargs = {
"in_channels": in_channels,
"out_channels": num_classes,
"backbone": model,
"pretrained": is_pretrained,
"spatial_dims": spatial_dim,
"norm": norm,
}
ret_tests.append(
[
kwargs,
(batch, in_channels) + (input_shape,) * spatial_dim,
(batch, num_classes) + (input_shape,) * spatial_dim,
]
)
for upsample_method in upsample:
if ("resnet" in model) and is_pretrained:
continue
kwargs = {
"in_channels": in_channels,
"out_channels": num_classes,
"backbone": model,
"pretrained": is_pretrained,
"spatial_dims": spatial_dim,
"norm": norm,
"upsample": upsample_method,
}
ret_tests.append(
[
kwargs,
(batch, in_channels) + (input_shape,) * spatial_dim,
(batch, num_classes) + (input_shape,) * spatial_dim,
]
)
return ret_tests


Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from monai.utils.type_conversion import convert_data_type

nib, _ = optional_import("nibabel")
http_error, has_requests = optional_import("requests", name="HTTPError")
http_error, has_req = optional_import("requests", name="HTTPError")

quick_test_var = "QUICKTEST"
_tf32_enabled = None
Expand Down Expand Up @@ -126,7 +126,7 @@ def assert_allclose(
def skip_if_downloading_fails():
try:
yield
except (ContentTooShortError, HTTPError, ConnectionError) + (http_error,) if has_requests else () as e:
except (ContentTooShortError, HTTPError, ConnectionError) + (http_error,) if has_req else () as e: # noqa: B030
raise unittest.SkipTest(f"error while downloading: {e}") from e
except ssl.SSLError as ssl_e:
if "decryption failed" in str(ssl_e):
Expand Down