LoginSignup
6
4

More than 5 years have passed since last update.

Inception V3 モジュール 実装

Last updated at Posted at 2018-11-27

構造

image.png

実装

def InceptionV3_block1():
    def f(x):
        b1 = Convolution2D(64, (1,1), strides=2, padding='same')(x)
        b1 = BatchNormalization()(b1)
        b1 = Activation('relu')(b1)

        b2 = Convolution2D(48, (1,1))(x)
        b2 = BatchNormalization()(b2)
        b2 = Activation('relu')(b2)
        b2 = Convolution2D(96, (3,3), strides=2, padding='same')(b2)
        b2 = BatchNormalization()(b2)
        b2 = Activation('relu')(b2)


        b3 = AveragePooling2D(pool_size=(3, 3), strides=2,  padding='same')(x)
        b3 = Convolution2D(64, (3,3), padding='same')(b3)
        b3 = BatchNormalization()(b3)
        b3 = Activation('relu')(b3)

        b4 = Convolution2D(64, (1,1))(x)
        b4 = BatchNormalization()(b4)
        b4 = Activation('relu')(b4)
        b4 = Convolution2D(96, (3,3), padding='same')(b4)
        b4 = BatchNormalization()(b4)
        b4 = Activation('relu')(b4)
        b4 = Convolution2D(32, (3,3),strides=2, padding='same')(b4)
        b4 = BatchNormalization()(b4)
        b4 = Activation('relu')(b4)

        output = concatenate([b1, b2, b3, b4], axis=-1)
        return output
    return f

def InceptionV3_block2():
    def f(x):
        b1 = Convolution2D(64, (1,1), strides=2,  padding='same')(x)
        b1 = BatchNormalization()(b1)
        b1 = Activation('relu')(b1)

        b2 = Convolution2D(48, (1,1))(x)
        b2 = BatchNormalization()(b2)
        b2 = Activation('relu')(b2)
        b2 = Convolution2D(96, (3,3), strides=2,  padding='same')(b2)
        b2 = BatchNormalization()(b2)
        b2 = Activation('relu')(b2)


        b3 = AveragePooling2D(pool_size=(3, 3), strides=2,  padding='same')(x)
        b3 = Convolution2D(64, (3,3), padding='same')(b3)
        b3 = BatchNormalization()(b3)
        b3 = Activation('relu')(b3)

        b4 = Convolution2D(64, (1,1))(x)
        b4 = BatchNormalization()(b4)
        b4 = Activation('relu')(b4)
        b4 = Convolution2D(96, (3,3), padding='same')(b4)
        b4 = BatchNormalization()(b4)
        b4 = Activation('relu')(b4)
        b4 = Convolution2D(64, (3,3),strides=2, padding='same')(b4)
        b4 = BatchNormalization()(b4)
        b4 = Activation('relu')(b4)

        output = concatenate([b1, b2, b3, b4], axis=-1)
        return output
    return f
def InceptionV3():
    inputs = Input(shape=(32, 32, 3))
    x = Convolution2D(32, (1,1), strides=2)(inputs)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
    x = MaxPooling2D((3, 3), strides=(2,2), padding='same')(x)

    x = InceptionV3_block1()(x)
    x = InceptionV3_block2()(x)

    x = GlobalAveragePooling2D()(x)
    x = Dense(10, kernel_initializer='he_normal', activation='softmax')(x)

    model = Model(inputs=inputs, outputs=x)
    return model

model = InceptionV3()
adam = Adam()
model.compile(optimizer=adam, loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4