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)")
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(64, (3, 3), strides=(2, 2), name='conv1')(img_input)
x = Conv2D(64, (3, 3), strides=(2, 2), name='conv2')(x)
x = BatchNormalization(axis=3, name='bn_conv1')(x)
x = Activation('relu')(x)
x = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding='same', name='pool1')(x)
x = Conv2D(128, (3, 3), strides=(2, 2), name='conv3')(x)
x = Conv2D(128, (3, 3), strides=(2, 2), name='conv4')(x)
x = BatchNormalization(axis=3, name='bn_conv2')(x)
x = Activation('relu')(x)
x = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding='same', name='pool2')(x)
x = Conv2D(256, (3, 3), strides=(2, 2), name='conv5')(x)
x = Conv2D(256, (3, 3), strides=(2, 2), name='conv6')(x)
x = BatchNormalization(axis=3, name='bn_conv3')(x)
x = Activation('relu')(x)
x = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding='same', name='pool3')(x)
x = Conv2D(512, (3, 3), strides=(2, 2), name='conv7')(x)
x = Conv2D(512, (3, 3), strides=(2, 2), name='conv8')(x)
x = BatchNormalization(axis=3, name='bn_conv4')(x)
x = Activation('relu')(x)
x = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding='same', name='pool4')(x)
x = Conv2D(512, (3, 3), strides=(2, 2), name='conv9')(x)
x = Conv2D(512, (3, 3), strides=(2, 2), name='conv10')(x)
x = BatchNormalization(axis=3, name='bn_conv5')(x)
x = Activation('relu')(x)
x = MaxPool2D(pool_size=(2, 2), strides=(2, 2), padding='same', name='pool5')(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='ImageNet Model')
return self.model
评论列表
文章目录