he Code is here:
import torch from torchvision.models import alexnet if __name__ == "__main__": net = alexnet() x = torch.rand((1, 3, 224, 224)) for name, layer in net.named_children(): x = layer(x) print(name, ' output shape:\t', x.shape)
The output is here:
features output shape: torch.Size([1, 256, 6, 6]) avgpool output shape: torch.Size([1, 256, 6, 6]) File "AlexNet.py", line 9, in <module> x = layer(x) RuntimeError: size mismatch, m1: [1536 x 6], m2: [9216 x 4096]
I want to test the input and output of the AlexNet, but i failed with the ‘size mismatch’ error. i use the image size(3,224,224) provided by the paper of AlexNet, and i wanna get the right output. After this error, i try to fix the
self.avgpool = nn.AdaptiveAvgPool2d((6, 6))
self.avgpool = nn.AdaptiveAvgPool2d((1, 9216))
and i get the right output.
I really want to know what did i do wrong with the torchvision. And i also want to know what people would do when they need to test the input and output of the cnn.
thx for your help!