Description
🐛 Describe the bug
Bug
I was going through the vision source code and I found a bug in function resnet_fpn_backbone in the module torchvision/models/detection/backbone_utils.py
.
According to the docstring of resnet_fpn_backbone
, one of the possible values for the parameter backbone_name
is 'ResNet'
.
However, passing 'ResNet'
to the function results in the following run time error:
============================= test session starts ==============================
collecting ... collected 1 item
test_found_n1.py::test_resnet_fpn_backbone FAILED [100%]
test_mohrez/test_found_n1.py:4 (test_resnet_fpn_backbone)
Traceback (most recent call last):
File "/home/moe/vision/test_mohrez/test_found_n1.py", line 7, in test_resnet_fpn_backbone
y = resnet_fpn_backbone(backbone_name='ResNet', pretrained=False)(x)
File "/home/moe/vision/torchvision/models/detection/backbone_utils.py", line 103, in resnet_fpn_backbone
backbone = resnet.__dict__[backbone_name](
TypeError: __init__() got an unexpected keyword argument 'pretrained'
======================== 1 failed, 2 warnings in 1.03s =========================
Process finished with exit code 1
To Reproduce
Running the following test reproduces the bug.
import torch
from torchvision.models.detection.backbone_utils import resnet_fpn_backbone
def test_resnet_fpn_backbone():
x = torch.rand(1, 3, 300, 300, dtype=torch.float32, device='cpu')
y = resnet_fpn_backbone(backbone_name='ResNet', pretrained=False)(x)
Reason
I think the reason behind this bug is that the constructor of the class ResNet in module torchvision/models/resnet.py
does not have a parameter named pretrained
. Therefore, function resnet_fpn_backbone
should check the value of the parameter backbone_name
, before reaching line 92. If it is ‘ResNet’
, it should act differently.
Versions
Collecting environment information...
PyTorch version: 1.10.1
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A
OS: Ubuntu 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31
Python version: 3.8.12 (default, Oct 12 2021, 13:49:34) [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.11.0-46-generic-x86_64-with-glibc2.17
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Versions of relevant libraries:
[pip3] mypy==0.931
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.21.2
[pip3] torch==1.10.1
[pip3] torchaudio==0.10.1
[pip3] torchvision==0.11.0a0+e7ec7e2
[conda] blas 1.0 mkl
[conda] cudatoolkit 11.3.1 h2bc3f7f_2
[conda] mkl 2021.4.0 h06a4308_640
[conda] mkl-service 2.4.0 py38h7f8727e_0
[conda] mkl_fft 1.3.1 py38hd3c417c_0
[conda] mkl_random 1.2.2 py38h51133e4_0
[conda] mypy 0.931 pypi_0 pypi
[conda] mypy-extensions 0.4.3 pypi_0 pypi
[conda] numpy 1.21.2 py38h20f2e39_0
[conda] numpy-base 1.21.2 py38h79a1101_0
[conda] pytorch 1.10.1 py3.8_cuda11.3_cudnn8.2.0_0 pytorch
[conda] pytorch-mutex 1.0 cuda pytorch
[conda] torchaudio 0.10.1 py38_cu113 pytorch
[conda] torchvision 0.11.0a0+e7ec7e2 dev_0