how to print the size of the particular layer in pytorch

Solutions on MaxInterview for how to print the size of the particular layer in pytorch by the best coders in the world

showing results for - "how to print the size of the particular layer in pytorch"
Gaia
04 Mar 2020
1from torchvision import models
2from summary import summary
3
4vgg = models.vgg16()
5summary(vgg, (3, 224, 224))
6
7----------------------------------------------------------------
8        Layer (type)               Output Shpae         Param #
9================================================================
10            Conv2d-1         [-1, 64, 224, 224]            1792
11              ReLU-2         [-1, 64, 224, 224]               0
12            Conv2d-3         [-1, 64, 224, 224]           36928
13              ReLU-4         [-1, 64, 224, 224]               0
14         MaxPool2d-5         [-1, 64, 112, 112]               0
15            Conv2d-6        [-1, 128, 112, 112]           73856
16              ReLU-7        [-1, 128, 112, 112]               0
17            Conv2d-8        [-1, 128, 112, 112]          147584
18              ReLU-9        [-1, 128, 112, 112]               0
19        MaxPool2d-10          [-1, 128, 56, 56]               0
20           Conv2d-11          [-1, 256, 56, 56]          295168
21             ReLU-12          [-1, 256, 56, 56]               0
22           Conv2d-13          [-1, 256, 56, 56]          590080
23             ReLU-14          [-1, 256, 56, 56]               0
24           Conv2d-15          [-1, 256, 56, 56]          590080
25             ReLU-16          [-1, 256, 56, 56]               0
26        MaxPool2d-17          [-1, 256, 28, 28]               0
27           Conv2d-18          [-1, 512, 28, 28]         1180160
28             ReLU-19          [-1, 512, 28, 28]               0
29           Conv2d-20          [-1, 512, 28, 28]         2359808
30             ReLU-21          [-1, 512, 28, 28]               0
31           Conv2d-22          [-1, 512, 28, 28]         2359808
32             ReLU-23          [-1, 512, 28, 28]               0
33        MaxPool2d-24          [-1, 512, 14, 14]               0
34           Conv2d-25          [-1, 512, 14, 14]         2359808
35             ReLU-26          [-1, 512, 14, 14]               0
36           Conv2d-27          [-1, 512, 14, 14]         2359808
37             ReLU-28          [-1, 512, 14, 14]               0
38           Conv2d-29          [-1, 512, 14, 14]         2359808
39             ReLU-30          [-1, 512, 14, 14]               0
40        MaxPool2d-31            [-1, 512, 7, 7]               0
41           Linear-32                 [-1, 4096]       102764544
42             ReLU-33                 [-1, 4096]               0
43          Dropout-34                 [-1, 4096]               0
44           Linear-35                 [-1, 4096]        16781312
45             ReLU-36                 [-1, 4096]               0
46          Dropout-37                 [-1, 4096]               0
47           Linear-38                 [-1, 1000]         4097000
48================================================================
49Total params: 138357544
50Trainable params: 138357544
51Non-trainable params: 0
52----------------------------------------------------------------