Ok, then you have to check your input, and make sure it is torch.tensor not a list or something else.
Because this code works without errors for me
model = models.densenet161(pretrained=False)
for param in model.parameters():
        param.requires_grad = False

model.classifier = nn.Sequential(nn.Linear(2208, 256),
                                    nn.ReLU(),
                                    nn.Dropout(0.2),
                                    nn.Linear(256, 10),
                                    nn.LogSoftmax(dim=1))
x = torch.rand(4, 3, 224, 224)
out = model.forward(x)

To see it is work you should reinitialize you model to remove hooks applied by torchsummury  function.