NVIDIA / partialconv

A New Padding Scheme: Partial Convolution based Padding
Other
1.21k stars 213 forks source link

Pretraining #3

Open bluesky314 opened 5 years ago

bluesky314 commented 5 years ago

You mentioned in the previous issue we can load pretrained and convert conv2d to partialconv. How would you change it as the model structure is fixed in pretrained models? My model is

`class convNet(torch.nn.Module):      # pretrained only taking till last 3 children of resnet18
    #constructor
    def __init__(self):
        super(convNet, self).__init__()
        resnet = models.resnet18(pretrained=True)
        self.mycut=torch.nn.Sequential(*list(resnet.children())[:-3])
        self.max_pool=torch.nn.MaxPool2d(2)
        self.conv1 = PartialConv2d(256,  256, kernel_size=3, stride=1, padding=1)
        self.conv2 = PartialConv2d(256, 256, kernel_size=3, stride=1, padding=1)

        self.Flattern=Lambda(flat)

        self.fc1=torch.nn.Linear(25600,120)
        self.fc2=torch.nn.Linear(120,50)
        self.fc3=torch.nn.Linear(50,8)

    def forward(self, x):
        x=self.mycut(x)
        x=F.relu(self.conv1(x))
        x=F.relu(self.conv2(x))

        x=self.Flattern(x)

        x=F.relu(self.fc1(x))
        x=F.relu(self.fc2(x))
        x=F.relu(self.fc3(x))
        return x` 

Using this makes your model train much slower than normal conv2d layers with fine tunning both off and on. How can i change all layers to PartialConv2d in the model above?

Also is there any plans to release a PartialConv3d? I would be interested in medical segmentation for that?

Thanks, Rahul

liuguilin1225 commented 5 years ago

In PyTorch, it is ok to load the pretrained weights as long as the layer names are the same even though their original layer types are different. For example, the networks in pd_resnet can load the pretrained weights of the corresponding networks in original models.resnet*. You can change your code: resnet = models.resnet18(pretrained=True) to: resnet = models.resnet18(pretrained=True)

And also change: model_urls = { 'pdresnet18': '', to be the original models_urls.resnet18.

Since only two of your layers are PartialConv2d, it should not be slow.

huseyinsavran commented 4 years ago

Hi, when I tried to load pretrained model of pdresnet50, it couldn't load because layer names of pretrained model did not match. there is "module." in front of layer names. I chaged them to "" on the RAM, then it loaded.