Understanding cnn models

Consider the code, starting with a can model based:


basemod = models.resnet34(pretrained=True)
b_list = list(self.basemod.children())
basemod_new = torch.nn.Sequential(*deepcopy(b_list))

My take on this was that basemod and basemod_new are the same model however basemod_new fails during inference with:

RuntimeError: size mismatch, m1: [2048 x 1], m2: [512 x 1]

Can someone explain what the problem is?

They are only the same, if your basemodel was using all layers in a sequential manner without any other calls.
In the resnet implementation you would lose the functional call to flatten.