self.maxpool=nn.MaxPool2d(2)

Just a suggestion. I think you could try nn.MaxPool2d(2) instead of using self.maxpool() repeatly. I don’t know whether it will cause a ploblem because all gradients flow through the node self.maxpool() (only one node) in graph.