pytorch-Alexnet 网络

Alexnet网络结构, 相比于LeNet,Alexnet加入了激活层Relu, 以及dropout层

第一层网络结构: 11x11x3x96, 步长为4, padding=2 

第二层网络结构: 5x5x96x256, 步长为1, padding=1

第三层网络结构: 3x3x256x384,步长为1, padding=1

第四层网络结构: 3x3x256x384,步长为1,padding=1 

第五层网络结构: 3x3x384x384, 步长为1,padding=1 

第六层网络结构: 3x3x384x256, 步长为1, padding=1

第七层网络结构: 进行维度变化, 进行dropout操作, 进行(256*6*6, 4096)全连接操作

第八层:进行dropout操作,进行全连接操作(4096, 4096) 

第九层: 输出层的操作, 进行全连接(4096, num_classes)

from torch import nn


class AlexNet(nn.Module):
    def __init__(self, num_classes):
        super(AlexNet, self).__init__()
        self.feature = nn.Sequential(
            nn.Conv2d(3, 96, kernel_size=11, stride=4, padding=2),
            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.classifier = nn.Sequential(
            nn.Dropout(),
            nn.Linear(256 * 6 * 6, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, 4096),
            nn.ReLU(inplace=True),
            nn.Linear(4096, num_classes),
        )

    def forward(self, x):
        x = self.feature(x)
        x = self.classifier(x)
        return x
    
原文地址:https://www.cnblogs.com/my-love-is-python/p/11729287.html