@bodokaiser, @fmassa thanks a lot!
I found the problem.
It is because the kernal size of avgpool layer  in resnet in the code is fixed
self.avgpool = nn.AvgPool2d(7)

so I think I should reimplement it by nn.AdaptiveAvgPool2d(1)
I think I also can redefine the avgpool in the forward function. I want to know is it feasible to redefine it when forward and why we should define all layer during init the module like most code.
Is there other way to define it in the init to have a changeable avgpool kernal size?