Resnet18 optimization

Hi everyone, I’m trying to use pretrained resnet18 for my project and it fits very good to my train data but not to validation data. I have tried changing batch size, convolutionlayers, lr_scheduler but there’s still no success.

This is my first project in DNN and I am a beginner. Can someone please give me a suggestion what can I do? Green is Train Loss and gray Validation Loss.

My Code looks like:

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

    self.resnet_model = models.resnet18(pretrained=True)
    self.resnet_model.conv1 = torch.nn.Conv2d(1, 64, kernel_size=(7,7), stride=(2,2), bias=True)
    self.resnet_model.conv2 = torch.nn.Conv2d(64, 32, kernel_size=(7,7), stride=(2,2), bias=True)
    self.resnet_model.conv3 = torch.nn.Conv2d(32, 64, kernel_size=(7,7), stride=(2,2), bias=True) 

def forward(self,x):
    x=self.resnet_model(x)
    return x

How large are your current training, validation, and test datasets?
Generally more samples help in this scenario. Additionally you could increase the regularization (such as adding or increasing dropout or adding weight decay), adding more data augmentation etc.
It can also be useful to check the training and validation datasets manually and make sure the samples come from the same domain and are thus “similar”.

Hi, thank you for your answer. I am using VoxCeleb 1 as my dataset and it contains 138361 files for training, 8251 for test and 6904 files for validation. There are 1251 speakers to be identified. I was using till now optim.SGD as my optimizer, now I’m trying optim.Adam. It is a bit better but I’m still not having results. Could ypu please give me an simple example how to increase dropout?

I have changed my model again:

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

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

def forward(self,x):

    x = self.resnet_model(x)
    return x

I think resnets don’t use dropout initially so you could add e.g. an nn.Sequential module as self.resnet_model.fc containing linear and dropout layers and could check, if it can improve the training.

It’s unfortunately still not working. Train Dataset works perfectly but Validation not. Can you please tell me how to check the Datasets manually?

Plot random images (or all) and check if the data might come from different domains, might contain different features, has special artifacts etc.