Created
September 24, 2019 13:58
-
-
Save mrtpk/10f4849cad54f9005861c2724a07349a to your computer and use it in GitHub Desktop.
VGG16 Implementaion in Keras
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def vgg16(input_shape=(224, 224, 3), classes=1000): | |
''' | |
ref: https://arxiv.org/abs/1409.1556 | |
default input_shape is 224, 224, 3 | |
default number of class is 1000 | |
''' | |
# import dependencies | |
# from keras.models import Model | |
# import keras.layers as layer | |
layer_input = layer.Input(shape=input_shape, name="input_layer") | |
# block1 | |
# conv3-64 | |
# conv3-64 | |
# maxPool | |
x = layer.Conv2D(filters=64, kernel_size=(3, 3), activation='relu', padding='same', name="block1_conv1")(layer_input) | |
x = layer.Conv2D(filters=64, kernel_size=(3, 3), activation='relu', padding='same', name="block1_conv2")(x) | |
x = layer.MaxPool2D(pool_size=(2, 2), strides=(2,2), name="block1_pool")(x) | |
# block2 | |
# conv3-128 | |
# conv3-128 | |
# maxPool | |
x = layer.Conv2D(filters=128, kernel_size=(3, 3), activation='relu', padding='same', name="block2_conv1")(x) | |
x = layer.Conv2D(filters=128, kernel_size=(3, 3), activation='relu', padding='same', name="block2_conv2")(x) | |
x = layer.MaxPool2D(pool_size=(2, 2), strides=(2,2), name="block2_pool")(x) | |
# block3 | |
# conv3-256 | |
# conv3-256 | |
# maxPool | |
x = layer.Conv2D(filters=256, kernel_size=(3, 3), activation='relu', padding='same', name="block3_conv1")(x) | |
x = layer.Conv2D(filters=256, kernel_size=(3, 3), activation='relu', padding='same', name="block3_conv2")(x) | |
x = layer.Conv2D(filters=256, kernel_size=(3, 3), activation='relu', padding='same', name="block3_conv3")(x) | |
x = layer.MaxPool2D(pool_size=(2, 2), strides=(2,2), name="block3_pool")(x) | |
# block4 | |
# conv3-512 | |
# conv3-512 | |
# conv3-512 | |
# maxPool | |
x = layer.Conv2D(filters=512, kernel_size=(3, 3), activation='relu', padding='same', name="block4_conv1")(x) | |
x = layer.Conv2D(filters=512, kernel_size=(3, 3), activation='relu', padding='same', name="block4_conv2")(x) | |
x = layer.Conv2D(filters=512, kernel_size=(3, 3), activation='relu', padding='same', name="block4_conv3")(x) | |
x = layer.MaxPool2D(pool_size=(2, 2), strides=(2,2), name="block4_pool")(x) | |
# block5 | |
# conv3-512 | |
# conv3-512 | |
# conv3-512 | |
# maxPool | |
x = layer.Conv2D(filters=512, kernel_size=(3, 3), activation='relu', padding='same', name="block5_conv1")(x) | |
x = layer.Conv2D(filters=512, kernel_size=(3, 3), activation='relu', padding='same', name="block5_conv2")(x) | |
x = layer.Conv2D(filters=512, kernel_size=(3, 3), activation='relu', padding='same', name="block5_conv3")(x) | |
x = layer.MaxPool2D(pool_size=(2, 2), strides=(2,2), name="block5_pool")(x) | |
# classification head | |
x = layer.Flatten(name='flatten')(x) | |
x = layer.Dense(units=4096, activation='relu', name="fc1")(x) | |
x = layer.Dense(units=4096, activation='relu', name="fc2")(x) | |
x = layer.Dense(units=classes, activation='softmax', name="fc3")(x) | |
return Model(inputs=layer_input, outputs=x, name='vgg16') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment