Skip to content

Instantly share code, notes, and snippets.

@dipanjanS
Created September 20, 2019 08:53
Show Gist options
  • Select an option

  • Save dipanjanS/fa878eef3af4f3f34df77c3268bf053c to your computer and use it in GitHub Desktop.

Select an option

Save dipanjanS/fa878eef3af4f3f34df77c3268bf053c to your computer and use it in GitHub Desktop.
INPUT_SHAPE_RN = (32, 32, 3)
def create_cnn_architecture_model2(input_shape):
inc_net = keras.applications.resnet50.ResNet50(include_top=False, weights='imagenet',
input_shape=input_shape)
inc_net.trainable = True
# Fine-tune the layers
for layer in inc_net.layers:
layer.trainable = True
base_inc = inc_net
base_out = base_inc.output
pool_out = keras.layers.Flatten()(base_out)
hidden1 = keras.layers.Dense(512, activation='relu')(pool_out)
drop1 = keras.layers.Dropout(rate=0.3)(hidden1)
hidden2 = keras.layers.Dense(512, activation='relu')(drop1)
drop2 = keras.layers.Dropout(rate=0.3)(hidden2)
out = keras.layers.Dense(10, activation='softmax')(drop2)
model = keras.Model(inputs=base_inc.input, outputs=out)
model.compile(optimizer=keras.optimizers.RMSprop(lr=1e-4),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
return model
model2 = create_cnn_architecture_model2(input_shape=INPUT_SHAPE_RN)
model2.summary()
# Output
Model: "model_3"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_4 (InputLayer) [(None, 32, 32, 3)] 0
__________________________________________________________________________________________________
conv1_pad (ZeroPadding2D) (None, 38, 38, 3) 0 input_4[0][0]
__________________________________________________________________________________________________
conv1 (Conv2D) (None, 16, 16, 64) 9472 conv1_pad[0][0]
__________________________________________________________________________________________________
...
...
dropout_5 (Dropout) (None, 512) 0 dense_8[0][0]
__________________________________________________________________________________________________
dense_9 (Dense) (None, 10) 5130 dropout_5[0][0]
==================================================================================================
Total params: 24,904,586
Trainable params: 24,851,466
Non-trainable params: 53,120
__________________________________________________________________________________________________
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment