コード例 #1
0
ファイル: GoogLeNetV12.py プロジェクト: wux024/LearnCNNs
    def __init__(self, num_classes=1000, version='v1'):
        super(GoogLeNetV12, self).__init__()
        self.conv1 = BasicConv2d(3, 64, kernel_size=7, stride=2, padding=3)
        self.maxpool1 = nn.MaxPool2d(3, 2, ceil_mode=True)
        self.conv2 = BasicConv2d(64, 64, kernel_size=1)
        self.conv3 = BasicConv2d(64, 192, kernel_size=3, stride=1, padding=1)
        self.maxpool2 = nn.MaxPool2d(3, 2, ceil_mode=True)

        self.inception3a = Inception(192, 64, 96, 128, 16, 32, 32, version)
        self.inception3b = Inception(256, 128, 128, 192, 32, 96, 64, version)

        self.maxpool3 = nn.MaxPool2d(3, 2, ceil_mode=True)

        self.inception4a = Inception(480, 192, 96, 208, 16, 48, 64, version)
        self.inception4b = Inception(512, 160, 112, 224, 24, 64, 64, version)
        self.inception4c = Inception(512, 128, 128, 256, 24, 64, 64, version)
        self.inception4d = Inception(512, 112, 144, 288, 32, 64, 64, version)
        self.inception4e = Inception(528, 256, 160, 320, 32, 128, 128, version)

        self.maxpool4 = nn.MaxPool2d(3, 2, ceil_mode=True)

        self.inception5a = Inception(832, 256, 160, 320, 32, 128, 128, version)
        self.inception5b = Inception(832, 384, 192, 384, 48, 128, 128, version)

        self.avgpool = nn.AvgPool2d(kernel_size=7, stride=1)

        self.dropout = nn.Dropout(p=0.4)

        self.fc = nn.Linear(1024, num_classes)
コード例 #2
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, k, l, m, n):
     super(Reduction_A, self).__init__()
     self.branch2 = BasicConv2d(in_channels,
                                n,
                                kernel_size=3,
                                stride=2,
                                padding=0,
                                bias=False)
     self.branch3 = nn.Sequential(
         BasicConv2d(in_channels,
                     k,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(k, l, kernel_size=3, stride=1, padding=1, bias=False),
         BasicConv2d(l, m, kernel_size=3, stride=2, padding=0, bias=False))
コード例 #3
0
ファイル: DenseNet.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, growth_rate, bn_size):
     super(_DenseLayer, self).__init__()
     self.add_module(
         'norm_relu_conv1',
         BasicConv2d(in_channels,
                     bn_size * growth_rate,
                     kernel_size=1,
                     stride=1,
                     bias=False))
     self.add_module(
         'norm_relu_conv2',
         BasicConv2d(bn_size * growth_rate,
                     growth_rate,
                     kernel_size=3,
                     stride=1,
                     padding=1,
                     bias=False))
コード例 #4
0
ファイル: DenseNet.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, out_channels):
     super(_Transition, self).__init__()
     self.add_module(
         'norm_relu_conv',
         BasicConv2d(in_channels,
                     out_channels,
                     kernel_size=1,
                     stride=1,
                     bias=False))
     self.add_module('pool', nn.AvgPool2d(kernel_size=2, stride=2))
コード例 #5
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, b1, b2_n1, b2_n1x3, b2_n3x1, n1_linear):
     super(InceptionC_res, self).__init__()
     self.branch1 = BasicConv2d(in_channels,
                                b1,
                                kernel_size=1,
                                stride=1,
                                padding=0,
                                bias=False)
     self.branch2 = nn.Sequential(
         BasicConv2d(in_channels,
                     b2_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b2_n1,
                     b2_n1x3,
                     kernel_size=(1, 3),
                     stride=(1, 1),
                     padding=(0, 1),
                     bias=False),
         BasicConv2d(b2_n1x3,
                     b2_n3x1,
                     kernel_size=(3, 1),
                     stride=(1, 1),
                     padding=(1, 0),
                     bias=False))
     self.conv_linear = nn.Conv2d(b1 + b2_n3x1,
                                  n1_linear,
                                  kernel_size=1,
                                  stride=1,
                                  padding=0,
                                  bias=False)
     self.short_cut = nn.Sequential()
     if in_channels != n1_linear:
         self.short_cut = nn.Sequential(
             nn.Conv2d(in_channels,
                       n1_linear,
                       kernel_size=1,
                       stride=1,
                       padding=0,
                       bias=False), nn.BatchNorm2d(n1_linear))
コード例 #6
0
ファイル: GoogLeNetV3.py プロジェクト: wux024/LearnCNNs
    def __init__(self, num_classes = 1000, version = 'v3'):
        # 299 x 299 x 3
        super(GoogLeNetV3, self).__init__()
        self.conv = nn.Sequential(
            BasicConv2d(3, 32, kernel_size=3, stride = 2),
            BasicConv2d(32, 32, kernel_size=3, stride = 1),
            BasicConv2d(32, 64, kernel_size=3, stride=1, padding = 1),
            nn.MaxPool2d(3,2),
            BasicConv2d(64, 80, kernel_size=3, stride=1),
            BasicConv2d(80, 192, kernel_size=3, stride=2),
            BasicConv2d(192, 288, kernel_size=3, stride=1, padding = 1)
        )

        self.inception3a = Inceptionv3_modelA(288, 64, 64, 96, 48, 64, 64)
        self.inception3b = Inceptionv3_modelA(288, 64, 64, 96, 48, 64, 64)
        self.inception3c = Inceptionv3_modelA(288, 0, 192, 384, 64, 96, 288)

        self.inception5a = Inceptionv3_modelB(768, 192, 160, 192, 160, 192, 192)
        self.inception5b = Inceptionv3_modelB(768, 192, 160, 192, 160, 192, 192)
        self.inception5c = Inceptionv3_modelB(768, 192, 160, 192, 160, 192, 192)
        self.inception5d = Inceptionv3_modelB(768, 192, 160, 192, 160, 192, 192)
        self.inception5e = Inceptionv3_modelB(768, 0, 192, 320, 192, 192, 768)

        self.inception2a = Inceptionv3_modelC(1280, 320, 384, 384, 448, 384, 192)
        self.inception2b = Inceptionv3_modelC(2048, 320, 384, 384, 448, 384, 192)

        self.pool = nn.MaxPool2d(8,1)

        self.fc = nn.Linear(2048, num_classes)
コード例 #7
0
ファイル: GoogLeNetV3.py プロジェクト: wux024/LearnCNNs
    def __init__(self, in_channels, out1_channels, out3in_channels, out3_channels, out5in_channels, out5_channels, outpool_channels):
        super(Inceptionv3_modelC, self).__init__()
        self.branch1 = BasicConv2d(in_channels, out1_channels, kernel_size=1)

        self.branch2_0 = BasicConv2d(in_channels, out3in_channels, kernel_size=1)
        self.branch2_1 = BasicConv2d(out3in_channels, out3_channels, kernel_size=(3, 1), padding = (1,0))
        self.branch2_2 = BasicConv2d(out3in_channels, out3_channels, kernel_size=(1, 3), padding = (0,1))

        self.branch3_0 = BasicConv2d(in_channels, out5in_channels, kernel_size=1)
        self.branch3_1 = nn.Sequential(
            BasicConv2d(out5in_channels, out5_channels, kernel_size=(3, 3), padding=1),
            BasicConv2d(out5_channels, out5_channels, kernel_size=(1, 3), padding = (0,1)),
        )
        self.branch3_2 = nn.Sequential(
            BasicConv2d(out5in_channels, out5_channels, kernel_size=(3, 3), padding=1),
            BasicConv2d(out5_channels, out5_channels, kernel_size=(3, 1), padding = (1,0)),
        )

        self.branch4 = nn.Sequential(
            nn.MaxPool2d(3, stride=1, padding=1),
            BasicConv2d(in_channels, outpool_channels, kernel_size=1)
        )
コード例 #8
0
ファイル: GoogLeNetV12.py プロジェクト: wux024/LearnCNNs
 def __init__(self,
              in_channels,
              out1_channels,
              out3in_channels,
              out3_channels,
              out5in_channels,
              out5_channels,
              outpool_channels,
              version='v1'):
     super(Inception, self).__init__()
     # 1x1 conv branch
     self.branch1 = BasicConv2d(in_channels, out1_channels, kernel_size=1)
     # 1x1 conv -> 3x3 conv branch
     self.branch2 = nn.Sequential(
         BasicConv2d(in_channels, out3in_channels, kernel_size=1),
         BasicConv2d(out3in_channels,
                     out3_channels,
                     kernel_size=3,
                     padding=1))
     # 1x1 conv ->  5x5 conv branch
     # 1x1 conv ->  3x3 conv branch ->  3x3 conv branch
     if version == 'v1':
         self.branch3 = nn.Sequential(
             BasicConv2d(in_channels, out5in_channels, kernel_size=1),
             BasicConv2d(out5in_channels,
                         out5_channels,
                         kernel_size=3,
                         padding=1))
     elif version == 'v2':
         self.branch3 = nn.Sequential(
             BasicConv2d(in_channels, out5in_channels, kernel_size=1),
             BasicConv2d(out5in_channels,
                         out5_channels,
                         kernel_size=3,
                         padding=1),
             BasicConv2d(out5_channels,
                         out5_channels,
                         kernel_size=3,
                         padding=1))
     # 3x3 pool -> 1x1 conv branch
     self.branch4 = nn.Sequential(
         nn.MaxPool2d(3, stride=1, padding=1),
         BasicConv2d(in_channels, outpool_channels, kernel_size=1))
コード例 #9
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, b1, b2_n1, b2_n3, b3_n1, b3_n3_1, b3_n3_2,
              n1_linear):
     super(Inception_A_res, self).__init__()
     self.branch1 = BasicConv2d(in_channels,
                                b1,
                                kernel_size=1,
                                stride=1,
                                padding=0,
                                bias=False)
     self.branch2 = nn.Sequential(
         BasicConv2d(in_channels,
                     b2_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b2_n1,
                     b2_n3,
                     kernel_size=3,
                     stride=1,
                     padding=1,
                     bias=False),
     )
     self.branch3 = nn.Sequential(
         BasicConv2d(in_channels,
                     b3_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b3_n1,
                     b3_n3_1,
                     kernel_size=3,
                     stride=1,
                     padding=1,
                     bias=False),
         BasicConv2d(b3_n3_1,
                     b3_n3_2,
                     kernel_size=3,
                     stride=1,
                     padding=1,
                     bias=False))
     self.conv_linear = nn.Conv2d(b1 + b2_n3 + b3_n3_2,
                                  n1_linear,
                                  1,
                                  1,
                                  0,
                                  bias=True)
     self.short_cut = nn.Sequential()
     if in_channels != n1_linear:
         self.short_cut = nn.Sequential(
             nn.Conv2d(in_channels,
                       n1_linear,
                       kernel_size=1,
                       stride=1,
                       padding=0,
                       bias=False), nn.BatchNorm2d(n1_linear))
コード例 #10
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, b2_n1, b2_n3, b3_n1, b3_n3, b4_n1, b4_n3_1,
              b4_n3_2):
     super(Reduction_B_Res, self).__init__()
     self.branch2 = nn.Sequential(
         BasicConv2d(in_channels,
                     b2_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b2_n1,
                     b2_n3,
                     kernel_size=3,
                     stride=2,
                     padding=0,
                     bias=False),
     )
     self.branch3 = nn.Sequential(
         BasicConv2d(in_channels,
                     b3_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b3_n1,
                     b3_n3,
                     kernel_size=3,
                     stride=2,
                     padding=0,
                     bias=False))
     self.branch4 = nn.Sequential(
         BasicConv2d(in_channels,
                     b4_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b4_n1,
                     b4_n3_1,
                     kernel_size=3,
                     stride=1,
                     padding=1,
                     bias=False),
         BasicConv2d(b4_n3_1,
                     b4_n3_2,
                     kernel_size=3,
                     stride=2,
                     padding=0,
                     bias=False))
コード例 #11
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, b1, b2, b3_n1, b3_n3, b4_n1, b4_n3):
     super(Inception_A, self).__init__()
     self.branch1 = nn.Sequential(
         nn.AvgPool2d(3, 1, 1),
         BasicConv2d(in_channels,
                     b1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False))
     self.branch2 = BasicConv2d(in_channels,
                                b2,
                                kernel_size=1,
                                stride=1,
                                padding=0,
                                bias=False)
     self.branch3 = nn.Sequential(
         BasicConv2d(in_channels,
                     b3_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b3_n1,
                     b3_n3,
                     kernel_size=3,
                     stride=1,
                     padding=1,
                     bias=False))
     self.branch4 = nn.Sequential(
         BasicConv2d(in_channels,
                     b4_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b4_n1,
                     b4_n3,
                     kernel_size=3,
                     stride=1,
                     padding=1,
                     bias=False),
         BasicConv2d(b4_n3,
                     b4_n3,
                     kernel_size=3,
                     stride=1,
                     padding=1,
                     bias=False))
コード例 #12
0
ファイル: GoogLeNetV3.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, out1_channels, out3in_channels, out3_channels, out5in_channels, out5_channels, outpool_channels):
     super(Inceptionv3_modelA, self).__init__()
     self.out1_channels = out1_channels
     stride = 1 if out1_channels > 0 else 2
     padding = 1 if out1_channels > 0 else 0
     if out1_channels > 0:
         self.branch1 = BasicConv2d(in_channels, out1_channels, kernel_size=1)
     # 1x1 conv -> 3x3 conv branch
     self.branch2 = nn.Sequential(
         BasicConv2d(in_channels, out3in_channels, kernel_size=1),
         BasicConv2d(out3in_channels, out3_channels, kernel_size=3, stride=stride, padding=padding)
     )
     # 1x1 conv ->  3x3 conv branch ->  3x3 conv branch
     self.branch3 = nn.Sequential(
         BasicConv2d(in_channels, out5in_channels, kernel_size=1),
         BasicConv2d(out5in_channels, out5_channels, kernel_size=3, padding=1),
         BasicConv2d(out5_channels, out5_channels, kernel_size=3, stride=stride, padding=padding)
     )
     # 3x3 pool -> 1x1 conv branch
     self.branch4 = nn.Sequential(
         nn.MaxPool2d(3, stride=stride, padding=padding),
         BasicConv2d(in_channels, outpool_channels, kernel_size=1)
     )
コード例 #13
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, b2_n1, b2_n3, b3_n1, b3_n1x7, b3_n7x1,
              b3_n3):
     super(Reduction_B_v4, self).__init__()
     self.branch2 = nn.Sequential(
         BasicConv2d(in_channels,
                     b2_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b2_n1,
                     b2_n3,
                     kernel_size=3,
                     stride=2,
                     padding=0,
                     bias=False))
     self.branch3 = nn.Sequential(
         BasicConv2d(in_channels,
                     b3_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b3_n1,
                     b3_n1x7,
                     kernel_size=(1, 7),
                     stride=(1, 1),
                     padding=(0, 3),
                     bias=False),
         BasicConv2d(b3_n1x7,
                     b3_n7x1,
                     kernel_size=(7, 1),
                     stride=(1, 1),
                     padding=(3, 0),
                     bias=False),
         BasicConv2d(b3_n7x1,
                     b3_n3,
                     kernel_size=3,
                     stride=2,
                     padding=0,
                     bias=False))
コード例 #14
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self):
     super(Stem_Res1, self).__init__()
     self.stem = nn.Sequential(
         BasicConv2d(3, 32, kernel_size=3, stride=2, padding=0, bias=False),
         BasicConv2d(32, 32, kernel_size=3, stride=1, padding=0,
                     bias=False),
         BasicConv2d(32, 64, kernel_size=3, stride=1, padding=1,
                     bias=False), nn.MaxPool2d(3, 2, 0),
         BasicConv2d(64, 80, kernel_size=1, stride=1, padding=0,
                     bias=False),
         BasicConv2d(80,
                     192,
                     kernel_size=3,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(192,
                     256,
                     kernel_size=3,
                     stride=2,
                     padding=0,
                     bias=False))
コード例 #15
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, b1, b2, b3_n1, b3_n1x3_3x1, b4_n1, b4_n1x3,
              b4_n3x1, b4_n1x3_3x1):
     super(InceptionC, self).__init__()
     self.branch1 = nn.Sequential(
         nn.AvgPool2d(3, 1, 1),
         BasicConv2d(in_channels,
                     b1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False))
     self.branch2 = BasicConv2d(in_channels,
                                b2,
                                kernel_size=1,
                                stride=1,
                                padding=0,
                                bias=False)
     self.branch3_1 = BasicConv2d(in_channels,
                                  b3_n1,
                                  kernel_size=1,
                                  stride=1,
                                  padding=0,
                                  bias=False)
     self.branch3_1x3 = BasicConv2d(b3_n1,
                                    b3_n1x3_3x1,
                                    kernel_size=(1, 3),
                                    stride=(1, 1),
                                    padding=(0, 1),
                                    bias=False)
     self.branch3_3x1 = BasicConv2d(b3_n1,
                                    b3_n1x3_3x1,
                                    kernel_size=(3, 1),
                                    stride=(1, 1),
                                    padding=(1, 0),
                                    bias=False)
     self.branch4_1 = nn.Sequential(
         BasicConv2d(in_channels,
                     b4_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b4_n1,
                     b4_n1x3,
                     kernel_size=(1, 3),
                     stride=(1, 1),
                     padding=(0, 1),
                     bias=False),
         BasicConv2d(b4_n1x3,
                     b4_n3x1,
                     kernel_size=(3, 1),
                     stride=(1, 1),
                     padding=(1, 0),
                     bias=False))
     self.branch4_1x3 = BasicConv2d(b4_n3x1,
                                    b4_n1x3_3x1,
                                    kernel_size=(1, 3),
                                    stride=(1, 1),
                                    padding=(0, 1),
                                    bias=False)
     self.branch4_3x1 = BasicConv2d(b4_n3x1,
                                    b4_n1x3_3x1,
                                    kernel_size=(3, 1),
                                    stride=(1, 1),
                                    padding=(1, 0),
                                    bias=False)
コード例 #16
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self, in_channels, b1, b2, b3_n1, b3_n1x7, b3_n7x1, b4_n1,
              b4_n1x7_1, b4_n7x1_1, b4_n1x7_2, b4_n7x1_2):
     super(Inception_B, self).__init__()
     self.branch1 = nn.Sequential(
         nn.AvgPool2d(3, 1, 1),
         BasicConv2d(in_channels,
                     b1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False))
     self.branch2 = BasicConv2d(in_channels,
                                b2,
                                kernel_size=1,
                                stride=1,
                                padding=0,
                                bias=False)
     self.branch3 = nn.Sequential(
         BasicConv2d(in_channels,
                     b3_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b3_n1,
                     b3_n1x7,
                     kernel_size=(1, 7),
                     stride=(1, 1),
                     padding=(0, 3),
                     bias=False),
         BasicConv2d(b3_n1x7,
                     b3_n7x1,
                     kernel_size=(1, 7),
                     stride=(1, 1),
                     padding=(0, 3),
                     bias=False))
     self.branch4 = nn.Sequential(
         BasicConv2d(in_channels,
                     b4_n1,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(b4_n1,
                     b4_n1x7_1,
                     kernel_size=(1, 7),
                     stride=(1, 1),
                     padding=(0, 3),
                     bias=False),
         BasicConv2d(b4_n1x7_1,
                     b4_n7x1_1,
                     kernel_size=(7, 1),
                     stride=(1, 1),
                     padding=(3, 0),
                     bias=False),
         BasicConv2d(b4_n7x1_1,
                     b4_n1x7_2,
                     kernel_size=(1, 7),
                     stride=(1, 1),
                     padding=(0, 3),
                     bias=False),
         BasicConv2d(b4_n1x7_2,
                     b4_n7x1_2,
                     kernel_size=(7, 1),
                     stride=(1, 1),
                     padding=(3, 0),
                     bias=False))
コード例 #17
0
ファイル: GoogLeNetV4.py プロジェクト: wux024/LearnCNNs
 def __init__(self):
     super(Stem_v4_Res2, self).__init__()
     self.step1 = nn.Sequential(
         BasicConv2d(3, 32, kernel_size=3, stride=2, padding=0, bias=False),
         BasicConv2d(32, 32, kernel_size=3, stride=1, padding=0,
                     bias=False),
         BasicConv2d(32, 64, kernel_size=3, stride=1, padding=1,
                     bias=False))
     self.step2_pool = nn.MaxPool2d(3, 2, 0)
     self.step2_conv = BasicConv2d(64,
                                   96,
                                   kernel_size=3,
                                   stride=2,
                                   padding=0,
                                   bias=False)
     self.step3_1 = nn.Sequential(
         BasicConv2d(160,
                     64,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(64, 96, kernel_size=3, stride=1, padding=0,
                     bias=False))
     self.step3_2 = nn.Sequential(
         BasicConv2d(160,
                     64,
                     kernel_size=1,
                     stride=1,
                     padding=0,
                     bias=False),
         BasicConv2d(64,
                     64,
                     kernel_size=(7, 1),
                     stride=(1, 1),
                     padding=(3, 0),
                     bias=False),
         BasicConv2d(64,
                     64,
                     kernel_size=(1, 7),
                     stride=(1, 1),
                     padding=(0, 3),
                     bias=False),
         BasicConv2d(64, 96, kernel_size=3, stride=1, padding=0,
                     bias=False))
     self.step4_pool = nn.MaxPool2d(3, 2, 0)
     self.step4_conv = BasicConv2d(192,
                                   192,
                                   kernel_size=3,
                                   stride=2,
                                   padding=0,
                                   bias=False)