How can I change pretrained resnet model to accept single channel image?

I’m trying to use per-trained ResNet-18 model for binary classification with modification in input channel and kernel size of 1st Conv layer. What is the best way to do this? Also does this approach uses pretrained weight for conv1 layer?Currently I’m trying like this


someone told me this, but I have not tried it yet

1 Like
import torch
from torchvision.models import resnet18
net = resnet18(pretrained=False) # You should put 'True' here 
net.conv1 = torch.nn.Conv1d(1, 64, (7, 7), (2, 2), (3, 3), bias=False)
batch = torch.rand(4, 1, 224, 224) # in the NCHW format