AlexNet.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:Papers2Code 作者: rainer85ah 项目源码 文件源码
def build(self, input_shape=None, num_outputs=1000):
        """
                Args:
                    input_shape: The input shape in the form (nb_rows, nb_cols, nb_channels) TensorFlow Format!!
                    num_outputs: The number of outputs at final softmax layer
                Returns:
                    A compile Keras model.
                """
        if len(input_shape) != 3:
            raise Exception("Input shape should be a tuple like (nb_rows, nb_cols, nb_channels)")

        # (227, 227, 3)
        input_shape = _obtain_input_shape(input_shape, default_size=224, min_size=197,
                                          data_format=K.image_data_format(), include_top=True)
        img_input = Input(shape=input_shape)
        # x = ZeroPadding2D((3, 3))(img_input)
        x = Conv2D(96, (11, 11), strides=(4, 4), name='conv1')(img_input)
        # (55, 55, 96)
        x = MaxPool2D(pool_size=(3, 3), strides=(2, 2), padding='same', name='pool1')(x)
        # (27, 27, 96)
        x = BatchNormalization(axis=3, name='bn_conv1')(x)

        x = Conv2D(256, (5, 5), strides=(4, 4), name='conv2')(x)
        x = MaxPool2D(pool_size=(3, 3), strides=(2, 2), padding='same', name='pool2')(x)
        x = BatchNormalization(axis=3, name='bn_conv2')(x)

        x = Conv2D(384, (3, 3), strides=(1, 1), padding=1, name='conv3')(x)
        x = Conv2D(384, (3, 3), strides=(1, 1), padding=1, name='conv4')(x)
        x = Conv2D(256, (3, 3), strides=(1, 1), padding=1, name='conv5')(x)
        x = MaxPool2D(pool_size=(3, 3), strides=(2, 2), padding='same', name='pool3')(x)

        x = Dense(units=4096)(x)
        x = Dense(units=4096)(x)
        x = Dense(units=num_outputs)(x)
        x = Activation('softmax')(x)

        self.model = Model(inputs=img_input, outputs=x, name='AlexNet Model')
        return self.model
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号