pytorch / pytorch/vision

String parameter cannot be passed to `torchvision.ops.deform_conv2d`

Open
#6,394 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement module: ops
Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🐛 Describe the bug

Bug Explanation

The current implementation of torchvision.ops.deform_conv2d implicitly assumes that padding is passed as a tuple or an integer, this means that if the padding is passed as either "same" or "valid" then torchvision is going to parse it as padding = ("same").

Sample Code

import torch

X = torch.randn((1,3,5,5))
torchvision.ops.deform_conv2d(
            X,
            torch.randn([1, 2 * 1 * 3 * 3, 3, 3]), #offset
            torch.randn([1, 3, 3, 3]),
            torch.randn([1]),
            stride=1,
            padding="zero",
            dilation=1,
            mask=None,
        )

Stacktrace

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
d:\Documents\Python Scripts\test.ipynb Cell 13 in <cell line: 2>()
      [1](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=0) X = torch.randn((1,3,5,5))
----> [2](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=1) torchvision.ops.deform_conv2d(
      [3](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=2)             X,
      [4](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=3)             torch.randn([1, 2 * 1 * 3 * 3, 3, 3]), #offset
      [5](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=4)             torch.randn([1, 3, 3, 3]),
      [6](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=5)             torch.randn([1]),
      [7](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=6)             stride=1,
      [8](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=7)             padding="zero",
      [9](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=8)             dilation=1,
     [10](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=9)             mask=None,
     [11](vscode-notebook-cell:/d%3A/Documents/Python%20Scripts/test.ipynb#X14sZmlsZQ%3D%3D?line=10)         )

File d:\Installations\Anaconda\lib\site-packages\torchvision\ops\deform_conv.py:77, in deform_conv2d(input, offset, weight, bias, stride, padding, dilation, mask)
     74     bias = torch.zeros(out_channels, device=input.device, dtype=input.dtype)
     76 stride_h, stride_w = _pair(stride)
---> 77 pad_h, pad_w = _pair(padding)
     78 dil_h, dil_w = _pair(dilation)
     79 weights_h, weights_w = weight.shape[-2:]

ValueError: too many values to unpack (expected 2)
Versions
Collecting environment information...
PyTorch version: 1.12.1
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 Home
GCC version: (x86_64-posix-seh, Built by strawberryperl.com project) 8.3.0
Clang version: Could not collect
CMake version: version 3.24.0-rc1
Libc version: N/A

Python version: 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.19041-SP0
Is CUDA available: True
CUDA runtime version: 11.5.50
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1650
Nvidia driver version: 512.15
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.23.1
[pip3] numpydoc==1.4.0
[pip3] torch==1.12.1
[pip3] torch-tb-profiler==0.4.0
[pip3] torchaudio==0.12.1
[pip3] torchvision==0.13.1
[conda] blas                      1.0                         mkl
[conda] cudatoolkit               11.3.1               h59b6b97_2
[conda] mkl                       2021.4.0           haa95532_640
[conda] mkl-service               2.4.0            py38h2bbff1b_0
[conda] mkl_fft                   1.3.1            py38h277e83a_0
[conda] mkl_random                1.2.2            py38hf11a4ad_0
[conda] numpy                     1.23.1           py38h7a0a035_0
[conda] numpy-base                1.23.1           py38hca35cd5_0
[conda] numpydoc                  1.4.0            py38haa95532_0
[conda] pytorch                   1.12.1          py3.8_cuda11.3_cudnn8_0    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torch                     1.12.1                   pypi_0    pypi
[conda] torch-tb-profiler         0.4.0                    pypi_0    pypi
[conda] torchaudio                0.12.1               py38_cu113    pytorch
[conda] torchvision               0.13.1               py38_cu113    pytorch

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in torchvision/ops/deform_conv.py at deform_conv2d, where the stack trace shows padding being passed to _pair. Check the existing operator tests for padding coverage and determine the intended handling for the reported string values. Done means the supported string-padding behavior is explicit and covered by tests without breaking integer or tuple padding.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.