How to access the last layer of the give model

class PneumoniaCnnModel(BinaryClassificationBase):
def init(self):
super(PneumoniaCnnModel, self).init()
# Load pre-trained DenseNet-121 model
self.model = models.densenet121(pretrained=True)

    # Freeze all layers except the last convolutional layer
    for param in self.model.parameters():
        param.requires_grad = False

    # Unfreeze the parameters of the last convolutional layer
    for name, param in self.model.named_parameters():
        if 'denseblock4' in name:
            param.requires_grad = True
            self.last_convolution_layer = name

    # Replace classifier with a new linear layer
    num_features = self.model.classifier.in_features
    self.model.classifier = nn.Sequential(
        nn.Linear(num_features, 512),  # Example new layer
        nn.Linear(512, 1)  # Output 1 value for binary classification

def forward(self, x):
    # Pass through the model
    x = self.model(x)
    # Apply sigmoid activation function to the output
    x = torch.sigmoid(x)
    return x

def last_layer(self):
    return self.last_convolution_layer

The sequential layer should be indexable

def last_layer(self):
    return self.model.classifier[-1]