当前位置:   article > 正文

经典网络--Alexnet_imagenet比赛2012-2023准确率

imagenet比赛2012-2023准确率

Alexnet简介

AlexNet网络,是2012年ImageNet竞赛冠军,准确率达到57.1%,top 1-5 达到80.2%.

网络基本架构

论文地址

pytorch实现

说明:

  1. 有的实现输入为224,这是为了方便计算 (224-11)/4 + 1=55方便整除
  2. 这里没有实现LRN结构(据说效果不大)
# encoding: utf-8
# @Author : NanG
# create on 2021/8/19 11:34 下午
import torch
from torch import nn
from torch.nn import Conv2d, MaxPool2d, ReLU


class Alexnet(nn.Module):
    def __init__(self, num_classes=1000):
        super().__init__()
        #input=3*227*227,ouput=96*55*55   (227-11)/4 + 1 = 55
        self.conv1 = Conv2d(in_channels=3, out_channels=96, kernel_size=11,stride=4)
        self.relu1 = ReLU(inplace=True)
        #input 96*55*55  output=96*27*27
        self.pool1 = MaxPool2d(kernel_size=3, stride=2)

        #input=96*27*27  output=256*27*27
        self.conv2 = Conv2d(in_channels=96, out_channels=256, kernel_size=5,
                            padding=2,stride=1)
        self.relu2 = ReLU(inplace=True)
        #input=256*27*27 output=256*13*13
        self.pool2 = MaxPool2d(kernel_size=3, stride=2)

        #input=256*13*13   output=384*13*13
        self.conv3 = Conv2d(in_channels=256, out_channels=384, kernel_size=3, padding=1,
                            stride=1)
        self.relu3 = ReLU(inplace=True)
        #input=384*13*13  output=384*13*13
        self.conv4 = Conv2d(in_channels=384, out_channels=384, kernel_size=3,
                            padding=1,stride=1)
        self.relu4 = ReLU(inplace=True)

        #input=384*13*13  output= 256*13*13
        self.conv5 = Conv2d(in_channels=384, out_channels=256, kernel_size=3, padding=1)
        self.relu5 = ReLU(inplace=True)

        #input=256*13*13 output=256*6*6
        self.pool5 = MaxPool2d(kernel_size=3,stride=2)

        self.fc1 = nn.Linear(in_features=256*6*6, out_features=4096)
        self.fc2 = nn.Linear(in_features=4096, out_features=4096)
        self.fc3 = nn.Linear(in_features=4096, out_features=num_classes)

    def forward(self, x):
        x = self.conv1(x)
        x = self.relu1(x)
        x = self.pool1(x)

        x = self.conv2(x)
        x = self.relu2(x)
        x = self.pool2(x)

        x = self.conv3(x)
        x = self.relu3(x)

        x = self.conv4(x)
        x = self.relu4(x)

        x = self.conv5(x)
        x = self.relu5(x)
        x = self.pool5(x)

        x = x.view(-1, 256*6*6)
        x = self.fc1(x)
        x = self.fc2(x)
        x = self.fc3(x)
        return x

if __name__ == '__main__':
    net = Alexnet(num_classes=1000)
    # print(net)
    x = torch.randn(20, 3, 227, 227)
    y3 = net(x)
    print("y3的维度是:{}".format(y3.size()))
    print(y3)







  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/92570
推荐阅读
  

闽ICP备14008679号