Created
August 20, 2019 16:29
-
-
Save dipanjanS/46f788f5741b9ac0d77a0d152367ec85 to your computer and use it in GitHub Desktop.
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
INPUT_SHAPE = (192, 192, 3) | |
# load the pre-trained model | |
vgg = keras.applications.vgg19.VGG19(include_top=False, weights='imagenet', | |
input_shape=INPUT_SHAPE) | |
vgg.trainable = True | |
set_trainable = False | |
for layer in vgg.layers: | |
if layer.name in ['block5_conv1', 'block4_conv1']: | |
set_trainable = True | |
if set_trainable: | |
layer.trainable = True | |
else: | |
layer.trainable = False | |
# add custom dense and output layers | |
base_vgg = vgg | |
base_out = base_vgg.output | |
pool_out = keras.layers.Flatten()(base_out) | |
hidden1 = keras.layers.Dense(1024, activation='relu')(pool_out) | |
drop1 = keras.layers.Dropout(rate=0.2)(hidden1) | |
hidden2 = keras.layers.Dense(512, activation='relu')(drop1) | |
drop2 = keras.layers.Dropout(rate=0.2)(hidden2) | |
out = keras.layers.Dense(7, activation='softmax')(drop2) | |
model = keras.Model(inputs=base_vgg.input, outputs=out) | |
model.compile(optimizer=keras.optimizers.RMSprop(lr=1e-5), | |
loss='categorical_crossentropy', | |
metrics=[categorical_accuracy]) | |
model.summary() | |
# Output | |
Layer (type) Output Shape Param # | |
================================================================= | |
input_2 (InputLayer) (None, 192, 192, 3) 0 | |
_________________________________________________________________ | |
block1_conv1 (Conv2D) (None, 192, 192, 64) 1792 | |
_________________________________________________________________ | |
block1_conv2 (Conv2D) (None, 192, 192, 64) 36928 | |
_________________________________________________________________ | |
block1_pool (MaxPooling2D) (None, 96, 96, 64) 0 | |
_________________________________________________________________ | |
... | |
... | |
_________________________________________________________________ | |
dense_5 (Dense) (None, 512) 524800 | |
_________________________________________________________________ | |
dropout_4 (Dropout) (None, 512) 0 | |
_________________________________________________________________ | |
dense_6 (Dense) (None, 7) 3591 | |
================================================================= | |
Total params: 39,428,167 | |
Trainable params: 37,102,599 | |
Non-trainable params: 2,325,568 | |
_________________________________________________________________ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment