pytorch / pytorch/vision

NotImplementedError: Dilation > 1 not supported in BasicBlock on Resnet

Open
#2,121 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

🐛 Bug

I tried to obtain a deeplabv3_resnet34 version based on the code that you are using for getting the resnet50 and resnet101 version

To Reproduce

def deeplabv3_resnet34(pretrained=False, progress=True,
                       num_classes=21, aux_loss=None, **kwargs):
    """Constructs a DeepLabV3 model with a ResNet-34 backbone.

    Args:
        pretrained (bool): If True, returns a model pre-trained on COCO train2017 which
            contains the same classes as Pascal VOC
        progress (bool): If True, displays a progress bar of the download to stderr
    """
    return _load_model('deeplabv3', 'resnet34', pretrained, progress, num_classes, aux_loss, **kwargs)

Expected behavior

I expected it to being created correctly. However, it throws the next error:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-21-71ba71ca9be2> in <module>
----> 1 model=deeplabv3_resnet34(pretrained=False,num_classes=2)
      2 model.train()

~/Documents/TFG/seg/models/torchvision.py in deeplabv3_resnet34(pretrained, progress, num_classes, aux_loss, **kwargs)
     91         progress (bool): If True, displays a progress bar of the download to stderr
     92     """
---> 93     return _load_model('deeplabv3', 'resnet34', pretrained, progress, num_classes, aux_loss, **kwargs)
     94 
     95 def deeplabv3_resnet50(pretrained=False, progress=True,

~/Documents/TFG/seg/models/torchvision.py in _load_model(arch_type, backbone, pretrained, progress, num_classes, aux_loss, **kwargs)
     45     if pretrained:
     46         aux_loss = True
---> 47     model = _segm_resnet(arch_type, backbone, num_classes, aux_loss, **kwargs)
     48     if pretrained:
     49         arch = arch_type + '_' + backbone + '_coco'

~/Documents/TFG/seg/models/torchvision.py in _segm_resnet(name, backbone_name, num_classes, aux, pretrained_backbone)
     18     backbone = resnet.__dict__[backbone_name](
     19         pretrained=pretrained_backbone,
---> 20         replace_stride_with_dilation=[False, True, True])
     21 
     22     return_layers = {'layer4': 'out'}

~/anaconda3/envs/seg/lib/python3.7/site-packages/torchvision/models/resnet.py in resnet34(pretrained, progress, **kwargs)
    247     """
    248     return _resnet('resnet34', BasicBlock, [3, 4, 6, 3], pretrained, progress,
--> 249                    **kwargs)
    250 
    251 

~/anaconda3/envs/seg/lib/python3.7/site-packages/torchvision/models/resnet.py in _resnet(arch, block, layers, pretrained, progress, **kwargs)
    218 
    219 def _resnet(arch, block, layers, pretrained, progress, **kwargs):
--> 220     model = ResNet(block, layers, **kwargs)
    221     if pretrained:
    222         state_dict = load_state_dict_from_url(model_urls[arch],

~/anaconda3/envs/seg/lib/python3.7/site-packages/torchvision/models/resnet.py in __init__(self, block, layers, num_classes, zero_init_residual, groups, width_per_group, replace_stride_with_dilation, norm_layer)
    148                                        dilate=replace_stride_with_dilation[0])
    149         self.layer3 = self._make_layer(block, 256, layers[2], stride=2,
--> 150                                        dilate=replace_stride_with_dilation[1])
    151         self.layer4 = self._make_layer(block, 512, layers[3], stride=2,
    152                                        dilate=replace_stride_with_dilation[2])

~/anaconda3/envs/seg/lib/python3.7/site-packages/torchvision/models/resnet.py in _make_layer(self, block, planes, blocks, stride, dilate)
    191             layers.append(block(self.inplanes, planes, groups=self.groups,
    192                                 base_width=self.base_width, dilation=self.dilation,
--> 193                                 norm_layer=norm_layer))
    194 
    195         return nn.Sequential(*layers)

~/anaconda3/envs/seg/lib/python3.7/site-packages/torchvision/models/resnet.py in __init__(self, inplanes, planes, stride, downsample, groups, base_width, dilation, norm_layer)
     45             raise ValueError('BasicBlock only supports groups=1 and base_width=64')
     46         if dilation > 1:
---> 47             raise NotImplementedError("Dilation > 1 not supported in BasicBlock")
     48         # Both self.conv1 and self.downsample layers downsample the input when stride != 1
     49         self.conv1 = conv3x3(inplanes, planes, stride)

NotImplementedError: Dilation > 1 not supported in BasicBlock

cc @vfdev-5

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 at the deeplabv3_resnet34 entry point and the torchvision/models/resnet.py ResNet and BasicBlock code shown in the traceback. Reproduce the construction with replace_stride_with_dilation=[False, True, True]; done means the model is created without the NotImplementedError for dilation greater than one.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.