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

ImageFilter's filter_size arg #8127

Open
oseymour opened this issue Oct 3, 2024 · 0 comments · May be fixed by #8189
Open

ImageFilter's filter_size arg #8127

oseymour opened this issue Oct 3, 2024 · 0 comments · May be fixed by #8189

Comments

@oseymour
Copy link

oseymour commented Oct 3, 2024

Describe the bug
The docs say that NotImplementedError will be raised "when filter is a string and not in self.supported_filters". When I try to initialize a Gaussian filter with no filter_size arg, I get "ValueError: filter_size must be specified when specifying filters by string.". When I print out the support filters for ImageFilter, I get ['elliptical', 'gauss', 'laplace', 'mean', 'median', 'savitzky_golay', 'sharpen', 'sobel'].

To Reproduce
Steps to reproduce the behavior:

from monai.transforms import ImageFilter
import torch

x = torch.rand((1,10,10))
trans = ImageFilter(filter="gauss", sigma=2)
y = trans(x)

Expected behavior
When initializing a Gaussian filter, I shouldn't need to pass the filter_size arg.

Screenshots
n/a

Environment
Python 3.12.3

Ensuring you use the relevant python executable, please paste the output of:

================================
Printing MONAI config...
================================
MONAI version: 1.3.2
Numpy version: 1.25.2
Pytorch version: 2.4.0+cpu
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 59a7211070538586369afd4a01eca0a7fe2e742e
MONAI __file__: C:\Apps\Anaconda3\v3_9_7_x64\Local\lib\site-packages\monai\__init__.py

Optional dependencies:
Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION.
ITK version: NOT INSTALLED or UNKNOWN VERSION.
Nibabel version: 5.2.1
scikit-image version: 0.19.2
scipy version: 1.9.3
Pillow version: 9.2.0
Tensorboard version: 2.8.0
gdown version: NOT INSTALLED or UNKNOWN VERSION.
TorchVision version: 0.19.0+cpu
tqdm version: 4.64.1
lmdb version: NOT INSTALLED or UNKNOWN VERSION.
psutil version: 5.9.0
pandas version: 1.5.1
einops version: NOT INSTALLED or UNKNOWN VERSION.
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: 2.12.1
pynrrd version: NOT INSTALLED or UNKNOWN VERSION.
clearml version: NOT INSTALLED or UNKNOWN VERSION.

For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies


================================
Printing system config...
================================
System: Windows
Win32 version: ('10', '10.0.19045', 'SP0', 'Multiprocessor Free')
Win32 edition: Enterprise
Platform: Windows-10-10.0.19045-SP0
Processor: Intel64 Family 6 Model 186 Stepping 3, GenuineIntel
Machine: AMD64
Python version: 3.9.7
Process name: python.exe
Command: ['C:\\Apps\\Anaconda3\\v3_9_7_x64\\Local\\python.exe', '-c', 'import monai; monai.config.print_debug_info()']
Open files: [popenfile(path='C:\\Windows\\System32\\en-US\\KernelBase.dll.mui', fd=-1), popenfile(path='C:\\Windows\\System32\\en-US\\tzres.dll.mui', fd=-1), popenfile(path='C:\\Windows\\System32\\en-US\\kernel32.dll.mui', fd=-1)]
Num physical CPUs: 10
Num logical CPUs: 12
Num usable CPUs: 12
CPU usage (%): [37.8, 14.6, 45.1, 4.7, 7.3, 7.5, 4.4, 8.1, 14.5, 12.4, 8.0, 4.0]
CPU freq. (MHz): 1800
Load avg. in last 1, 5, 15 mins (%): [0.0, 0.0, 0.0]
Disk usage (%): 67.7
Avg. sensor temp. (Celsius): UNKNOWN for given OS
Total physical memory (GB): 31.4
Available memory (GB): 18.7
Used memory (GB): 12.6

================================
Printing GPU config...
================================
Num GPUs: 0
Has CUDA: False
cuDNN enabled: False
NVIDIA_TF32_OVERRIDE: None
TORCH_ALLOW_TF32_CUBLAS_OVERRIDE: None

Additional context
Add any other context about the problem here.

EloiNavet added a commit to EloiNavet/MONAI that referenced this issue Nov 4, 2024
Fixes Project-MONAI#8127

Update `ImageFilter` to handle Gaussian filter without requiring `filter_size`.

* Modify `monai/transforms/utility/array.py` to allow Gaussian filter without `filter_size`.
  - Adjust `_check_filter_format` method to skip `filter_size` check for Gaussian filter. Indeed Gauss filter is the only one in the list that doesn't require a filter_size.
* Add unit test in `tests/test_image_filter.py` for Gaussian filter without `filter_size`.
  - Verify output shape matches input shape.

Note that this method is compliant with the dictionnary version since this one load the fixed version.
EloiNavet added a commit to EloiNavet/MONAI that referenced this issue Nov 6, 2024
Fixes Project-MONAI#8127

Update `ImageFilter` to handle Gaussian filter without requiring `filter_size`.

* Modify `monai/transforms/utility/array.py` to allow Gaussian filter without `filter_size`.
  - Adjust `_check_filter_format` method to skip `filter_size` check for Gaussian filter. Indeed Gauss filter is the only one in the list that doesn't require a filter_size.
* Add unit test in `tests/test_image_filter.py` for Gaussian filter without `filter_size`.
  - Verify output shape matches input shape.

Note that this method is compliant with the dictionnary version since this one load the fixed version.

Signed-off-by: Eloi Navet <[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 a pull request may close this issue.

1 participant