I tried using pre-trained resnet-50 with image size of 400X400 and modified Conv1 input channel and kernel size. I didn’t get any error. How will be the weights initialized in this case.
import torch
import torchvision
import torch.nn as nn
from torchsummary import summary
from torchvision import datasets, models, transforms
model_ft = models.resnet50(pretrained=False)
model_ft.conv1=nn.Conv2d(1, 64, kernel_size=(3, 3), stride=(2, 2), padding=(3, 3), bias=False)
When I tried to print the summary I got
print(summary(model_ft.cuda(),input_size=(1,400,400)))
------------------------------------------------------------------------
Layer (type) Output Shape Param #
==========================================
Conv2d-1 [-1, 64, 202, 202] 576
BatchNorm2d-2 [-1, 64, 202, 202] 128
ReLU-3 [-1, 64, 202, 202] 0
MaxPool2d-4 [-1, 64, 101, 101] 0
Conv2d-5 [-1, 64, 101, 101] 4,096
Without modifying anything in pre-trained model, I got summary as
model_ft = models.resnet50(pretrained=True)
print(summary(model_ft.cuda(),input_size=(3,400,400)))
----------------------------------------------------------------
Layer (type) Output Shape Param #
=========================================
Conv2d-1 [-1, 64, 200, 200] 9,408
BatchNorm2d-2 [-1, 64, 200, 200] 128
ReLU-3 [-1, 64, 200, 200] 0
MaxPool2d-4 [-1, 64, 100, 100] 0
Conv2d-5 [-1, 64, 100, 100] 4,096
If I try to remove/change layers in pre-trained model, Pytorch doesn’t throw any error. How will be the weights are initilized after changing the pre-trained model?