speedinghzl / pytorch-segmentation-toolbox

PyTorch Implementations for DeeplabV3 and PSPNet
MIT License
772 stars 167 forks source link

Resnet architecture mismacthes. #38

Closed sbelharbi closed 5 years ago

sbelharbi commented 5 years ago

Hello, I wonder why your Resnet architecture mismatches standard Resnet architectures? It does not allow to use ImageNet pre-trained models.

Yours has two extra convolution layers; and there is no convolution layer with kernels 7x7.

Thanks!

Standard Resnet arch.:

https://github.com/speedinghzl/Pytorch-Deeplab https://github.com/kazuto1011/deeplab-pytorch https://github.com/isht7/pytorch-deeplab-resnet https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py

class ResNet(nn.Module):

    def __init__(self, block, layers, num_classes=1000, zero_init_residual=False):
        super(ResNet, self).__init__()
        self.inplanes = 64
        self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
                               bias=False)
        self.bn1 = nn.BatchNorm2d(64)
        self.relu = nn.ReLU(inplace=True)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
        self.layer1 = self._make_layer(block, 64, layers[0])
        self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
        self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
        self.layer4 = self._make_layer(block, 512, layers[3], stride=2)

...

Your Resnet arch.:

class ResNet(nn.Module):
    def __init__(self, block, layers, num_classes):
        self.inplanes = 128
        super(ResNet, self).__init__()
        self.conv1 = conv3x3(3, 64, stride=2)
        self.bn1 = BatchNorm2d(64)
        self.relu1 = nn.ReLU(inplace=False)
        self.conv2 = conv3x3(64, 64)
        self.bn2 = BatchNorm2d(64)
        self.relu2 = nn.ReLU(inplace=False)
        self.conv3 = conv3x3(64, 128)
        self.bn3 = BatchNorm2d(128)
        self.relu3 = nn.ReLU(inplace=False)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)

        self.relu = nn.ReLU(inplace=False)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1, ceil_mode=True) # change
        self.layer1 = self._make_layer(block, 64, layers[0])
        self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
        self.layer3 = self._make_layer(block, 256, layers[2], stride=1, dilation=2)
        self.layer4 = self._make_layer(block, 512, layers[3], stride=1, dilation=4, multi_grid=(1,1,1))

....
speedinghzl commented 5 years ago

Yes, this resnet arch is used in PSPnet.

You can use the MIT pretrained model mentioned in ReadMe for initialization.

sbelharbi commented 5 years ago

Thanks! resnet-101 does not fit the GPU. I'm trying to use resnet-50 (and to be able to use the default pre-trained model on ImageNet). I adjusted my code to do that. Thanks!

erichhhhho commented 5 years ago

@sbelharbi Hi, May I ask, does it make a difference between this two arch(con1 7x7 and conv1 3x3, inplanes64 and inplanes128)?

sbelharbi commented 5 years ago

not sure what do you mean. self.inplanes is independent of the size of the kernel self.conv1. the former is the the number of the input of planes of a block.

erichhhhho commented 5 years ago

@sbelharbi Thx for your reply. I meant, how is the performance when you used the resnet-50 Standard as backbone for PSPnet? Is it different much from the resnet backbone arch here?

sbelharbi commented 5 years ago

I can't tell. I ended up using a different architecture than PSPnet/deeplab (at the last layers) + resnet-101 as backbone for segmentation AND classification tasks (simultaneously). So, I can't really answer you.

I don't think that you can find a helpful answer to your question, but to perform your own experiments on your data. There are a lot of factors in play (task, data, number of samples, training scheme, ...). Such experiments may helpfully give you a hint on which direction to go.

The advantage of the implementations in this repo (deeplab + pspnet) is that you will be able to use pre-trained archs over segmentation task.