Resnet uses the name fc for its last layer while Densenet uses the name classifier for its last layer. You may see these naming and indexing by printing out the model
model = models.densenet161(pretrained=True)
print(model)