ResNet18 parameterlist is empty

Hi everyone, I’m trying to implement a resnet18 network for my dataset but I become an error: “optimizer got an empty parameter list”. May someone tell me what I have done wrong?

optimizer = optim.SGD(running_programm.parameters(), lr=0.01, momentum=0.9)

My network looks so:

class Resnet_Speaker_Recognition(nn.Module):
def init(self):
super(Resnet_Speaker_Recognition, self).init()

    resnet_model = models.resnet18(pretrained=True)
    resnet_model.conv1 = torch.nn.Conv2d(1, 64, kernel_size=(7, 7), stride=(2,2), padding=(3, 3), bias=False)
    num_ftrs = resnet_model.fc.in_features
    resnet_model.fc = nn.Linear(num_ftrs, 1251)

def forward(self,x):
    return x

I think you’re missing a bunch of self. in the init.

Best regards


P.S.: If you put triple backticks ``` before and after your code, you’ll get proper formatting.

1 Like

Thank you very much, it really helped me :slight_smile: