pytorch-Alexnet 网络

烈酒焚心 提交于 2019-12-02 03:36:16

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
    

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!