I changed self.avgpool = nn.AdaptiveAvgPool2d ((1, 1)) and self.fc = nn.Linear (512 * block.expansion, num_classes in the last layer and deleted the line torch.flatten (x, 1). I used nn.Softmax2d () and self.avgpool = nn.AdaptiveAvgPool2d ((256, 256)).