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

transforms.GaussianBlur cannot accomodate sizes claimed in documentation #7911

Closed
frotaur opened this issue Aug 29, 2023 · 2 comments · Fixed by #7978
Closed

transforms.GaussianBlur cannot accomodate sizes claimed in documentation #7911

frotaur opened this issue Aug 29, 2023 · 2 comments · Fixed by #7978

Comments

@frotaur
Copy link

frotaur commented Aug 29, 2023

🐛 Describe the bug

According to the doc, the GaussianBlur can take tensors of shape (...,C,H,W) where '...' is any number of dimension. This seems not to be the case. In this example :

import torch
from torchvision.transforms import GaussianBlur


a = GaussianBlur(5,sigma=1.)

img = torch.randn((5,6,3,10,10)) # (Of size (...,C,H,W))

img=a(img)

This yields :

Traceback (most recent call last):
  File "/home/vassilis/CASorter/runs/testblur.py", line 9, in <module>
    img=a(img)
  File "/home/vassilis/penv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/vassilis/penv/lib/python3.10/site-packages/torchvision/transforms/transforms.py", line 1819, in forward
    return F.gaussian_blur(img, self.kernel_size, [sigma, sigma])
  File "/home/vassilis/penv/lib/python3.10/site-packages/torchvision/transforms/functional.py", line 1386, in gaussian_blur
    output = F_t.gaussian_blur(t_img, kernel_size, sigma)
  File "/home/vassilis/penv/lib/python3.10/site-packages/torchvision/transforms/_functional_tensor.py", line 760, in gaussian_blur
    img = torch_pad(img, padding, mode="reflect")
NotImplementedError: Only 2D, 3D, 4D, 5D padding with non-constant padding are supported for now

Of course this is not 'game-breaking' since I can just reshape the extra dimension to a single leading batch dimension, but still, the behavior documented is incorrect.

Versions

Collecting environment information...
PyTorch version: 2.0.1+cu117
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64)
GCC version: (Ubuntu 4.9.3-13ubuntu2) 4.9.3
Clang version: Could not collect
CMake version: version 3.27.0
Libc version: glibc-2.27

Python version: 3.10.11 (main, Apr 5 2023, 14:15:30) [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-4.15.0-162-generic-x86_64-with-glibc2.27
Is CUDA available: True
CUDA runtime version: 9.1.85
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: Tesla V100-DGXS-32GB
GPU 1: Tesla V100-DGXS-32GB
GPU 2: Tesla V100-DGXS-32GB
GPU 3: Tesla V100-DGXS-32GB

Nvidia driver version: 460.106.00
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.3.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.3.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 40
On-line CPU(s) list: 0-39
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E5-2698 v4 @ 2.20GHz
Stepping: 1
CPU MHz: 1206.762
CPU max MHz: 3600.0000
CPU min MHz: 1200.0000
BogoMIPS: 4397.91
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 51200K
NUMA node0 CPU(s): 0-39
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap intel_pt xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts md_clear flush_l1d

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==2.0.1
[pip3] torch-tb-profiler==0.4.1
[pip3] torchenhanced==0.1.7
[pip3] torchvision==0.15.2
[pip3] triton==2.0.0
[conda] Could not collect

cc @svekars @carljparker @datumbox @vfdev-5 @pmeier

@pmeier pmeier transferred this issue from pytorch/pytorch Aug 30, 2023
@pmeier
Copy link
Collaborator

pmeier commented Sep 1, 2023

Thanks @frotaur for the report. Can confirm that the docs are wrong here. We accept a PR fixing that.

The v2 transforms, which will become the recommended ones starting with the upcoming release, handle this correctly:

import torch
from torchvision.transforms.v2 import GaussianBlur  # <-- note the v2 import


a = GaussianBlur(5,sigma=1.)

img = torch.randn((5,6,3,10,10)) # (Of size (...,C,H,W))

img=a(img)

@vilktor370
Copy link
Contributor

@pmeier

I submitted a PR to correct the doc. #7978

If other code needs to be changed, please let me know. I will be happy to work on it!

@pmeier pmeier linked a pull request Sep 21, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants