You can replace the last linear layer with an nn.Sequential module containing the described layers:
model = torchvision.models.resnet18(pretrained=False)
model.fc = nn.Sequential(
    nn.Linear(512, 100),
    nn.ReLU(),
    nn.Linear(100, 40),
    nn.ReLU(),
    nn.Linear(40, 20))
out = model(torch.randn(2, 3, 224, 224))
print(out.shape)
> torch.Size([2, 20])