Ah, this is a tricky one! I don’t think you have done anything obviously wrong, but the issue is due to the fact that there is a “functional” use of torch.flatten in ResNet18 which means that if you just append the modules you are missing an operation before the linear layer.
Can you check if changing the lines
model.add_module('final', nn.Sequential(*(list(resnet.children())[-4:])))
print(model)
summary(model.to(device), (3, 512, 1536))

to
rest = list(resnet.children())[-4:]
flatten = torch.nn.Flatten(1)
rest.insert(-1, flatten)
model.add_module('final', nn.Sequential(*rest))
print(model)
summary(model.to(device), (3, 512, 1536))

fixes the issue?