Skip to content

Use replication padding in Median filter#5329

Merged
wyli merged 5 commits intoProject-MONAI:devfrom
dzenanz:properMedian
Oct 14, 2022
Merged

Use replication padding in Median filter#5329
wyli merged 5 commits intoProject-MONAI:devfrom
dzenanz:properMedian

Conversation

@dzenanz
Copy link
Copy Markdown
Contributor

@dzenanz dzenanz commented Oct 13, 2022

Ref #5264. Follow-up to #5307. This is a more normal, intuitive variant of median filtering.

@dzenanz
Copy link
Copy Markdown
Contributor Author

dzenanz commented Oct 13, 2022

Docs for padding are the same in both version 1.9 and 1.12. Yet torch versions 1.9 and lower complain. Ideas?

======================================================================
FAIL: test_value_2 (tests.test_median_smoothd.TestMedianSmoothd)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
    return func(*(a + p.args), **p.kwargs)
  File "/home/runner/work/MONAI/MONAI/tests/test_median_smoothd.py", line 58, in test_value
    result = MedianSmoothd(**arguments)(image)
  File "/home/runner/work/MONAI/MONAI/monai/transforms/intensity/dictionary.py", line 1020, in __call__
    d[key] = self.converter(d[key])
  File "/home/runner/work/MONAI/MONAI/monai/transforms/intensity/array.py", line 1164, in __call__
    out_t: torch.Tensor = median_filter_instance(img_t)
  File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/runner/work/MONAI/MONAI/monai/networks/layers/simplelayers.py", line 555, in forward
    x = median_filter(x, kernel=self.kernel, spatial_dims=self.spatial_dims)
  File "/home/runner/work/MONAI/MONAI/monai/networks/layers/simplelayers.py", line 505, in median_filter
    padded_input: torch.Tensor = F.pad(in_tensor, pad=padding, mode="replicate")
  File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/torch/nn/functional.py", line 4157, in _pad
    assert len(pad) == 2, "3D tensors expect 2 values for padding"
AssertionError: 3D tensors expect 2 values for padding

======================================================================
FAIL: test_value_3 (tests.test_median_smoothd.TestMedianSmoothd)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
    return func(*(a + p.args), **p.kwargs)
  File "/home/runner/work/MONAI/MONAI/tests/test_median_smoothd.py", line 58, in test_value
    result = MedianSmoothd(**arguments)(image)
  File "/home/runner/work/MONAI/MONAI/monai/transforms/intensity/dictionary.py", line 1020, in __call__
    d[key] = self.converter(d[key])
  File "/home/runner/work/MONAI/MONAI/monai/transforms/intensity/array.py", line 1164, in __call__
    out_t: torch.Tensor = median_filter_instance(img_t)
  File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/runner/work/MONAI/MONAI/monai/networks/layers/simplelayers.py", line 555, in forward
    x = median_filter(x, kernel=self.kernel, spatial_dims=self.spatial_dims)
  File "/home/runner/work/MONAI/MONAI/monai/networks/layers/simplelayers.py", line 505, in median_filter
    padded_input: torch.Tensor = F.pad(in_tensor, pad=padding, mode="replicate")
  File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/torch/nn/functional.py", line 4168, in _pad
    assert len(pad) == 4, "4D tensors expect 4 values for padding"
AssertionError: 4D tensors expect 4 values for padding

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: Dženan Zukić <[email protected]>
@dzenanz
Copy link
Copy Markdown
Contributor Author

dzenanz commented Oct 14, 2022

@wyli any suggestions? Or take over the PR?

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Oct 14, 2022

sure @dzenanz, it should be just minor issues I 'll modify the PR directly...

@wyli
Copy link
Copy Markdown
Contributor

wyli commented Oct 14, 2022

/build

@wyli wyli enabled auto-merge (squash) October 14, 2022 18:50
@wyli wyli merged commit e081510 into Project-MONAI:dev Oct 14, 2022
@dzenanz dzenanz deleted the properMedian branch October 14, 2022 21:30
bhashemian pushed a commit to JHancox/MONAI that referenced this pull request Oct 20, 2022
Ref Project-MONAI#5264. Follow-up to Project-MONAI#5307. This is a more normal, intuitive variant
of median filtering.

Signed-off-by: Dženan Zukić <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Co-authored-by: Wenqi Li <[email protected]>
Co-authored-by: Wenqi Li <[email protected]>
Signed-off-by: Behrooz <[email protected]>
wyli added a commit that referenced this pull request Oct 24, 2022
Ref #5264. Follow-up to #5307. This is a more normal, intuitive variant
of median filtering.

Signed-off-by: Dženan Zukić <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Co-authored-by: Wenqi Li <[email protected]>
Co-authored-by: Wenqi Li <[email protected]>
wyli added a commit that referenced this pull request Oct 24, 2022
Ref #5264. Follow-up to #5307. This is a more normal, intuitive variant
of median filtering.

Signed-off-by: Dženan Zukić <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Co-authored-by: Wenqi Li <[email protected]>
Co-authored-by: Wenqi Li <[email protected]>
KumoLiu pushed a commit that referenced this pull request Nov 2, 2022
Ref #5264. Follow-up to #5307. This is a more normal, intuitive variant
of median filtering.

Signed-off-by: Dženan Zukić <[email protected]>
Signed-off-by: Wenqi Li <[email protected]>
Co-authored-by: Wenqi Li <[email protected]>
Co-authored-by: Wenqi Li <[email protected]>
Signed-off-by: KumoLiu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants