I’m trying to replace the last layer of an imagenet trained model.
model_imagenet = models.resnet18(pretrained=True)
model_imagenet

class ResNetNewTop(nn.Module):
    def __init__(self, old_model, num_classes=2):
        super(ResNetNewTop, self).__init__()
        self.bottom = nn.Sequential(*list(old_model.children())[:-1])
        self.top = nn.Linear(512, num_classes)  # TODO: input size (512) from bottom

    def forward(self, x):
        x = self.bottom(x)
        x = self.top(x)  # <<< Errors here
        return x

model = ResNetNewTop(model_imagenet, num_classes=2)
model.cuda()
model

This is throwing
RuntimeError: matrix and matrix expected at [snip] /torch/lib/THC/generic/THCTensorMathBlas.cu:235
Can I put Sequential() into a new model directly? Or do I have to loop through the layers and build up the model that way?