pytorch 卷积层到全连接层的参数个数

import torch
from torch import nn
from torch.autograd import Variable


class AlexNet(nn.Module):
    def __init__(self):
        super(AlexNet, self).__init__()
        self.conv_unit = nn.Sequential(
            nn.Conv2d(3, 96, kernel_size=11, stride=4),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2),
            nn.Conv2d(96, 256, kernel_size=5, padding=2),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2),
            nn.Conv2d(256, 384, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(384, 384, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(384, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2))
        # self.fc=nn.Sequential(
        #     nn.Linear(???, 4096))

    def forward(self, x):
        x = self.conv_unit(x)
        print(x.size())


if __name__ == '__main__':
    net = AlexNet()
    data_input = Variable(torch.randn([1, 3, 96, 96])) # 这里假设输入图片是96x96
    print(data_input.size())
    net(data_input)

 

你可能感兴趣的:(pytorch)