I want to modify the resnet model imported from torchvision.models, but the default input is 3-channel matrix.
I tried to rebuild a Net class as below:
class Net(nn.Module):
def init(self, base):
super(Net, self).init()
num_ftrs = base.fc.in_features
self.conv1 = nn.Conv2d(4, 64, kernel_size=(7,7), stride=(2,2), padding=(3,3), bias=False)
self.base_model = nn.Sequential(
*list(base.children())[1:]
)
self.fc = nn.Linear(num_ftrs, 17)
def forward(self, x):
    x = self.conv1(x)
    x = x.view(10, 64, 128, 128) #batchsize is 10, image size is 256x256
    feature = self.base_model(x)
    out = self.fc(feature)
    return F.sigmoid(out)

base_model = models.resnet50()
model = Net(base_model)
but errors are:
RuntimeError: matrix and matrix expected at /b/wheel/pytorch-src/torch/lib/THC/generic/THCTensorMathBlas.cu:237