Skip to content

Instantly share code, notes, and snippets.

@nonlinearjunkie
Last active July 1, 2020 10:33
Show Gist options
  • Save nonlinearjunkie/9d7e56d7f8dd5cbe28bcec72ca96960f to your computer and use it in GitHub Desktop.
Save nonlinearjunkie/9d7e56d7f8dd5cbe28bcec72ca96960f to your computer and use it in GitHub Desktop.
base_model = tf.keras.applications.MobileNetV2(input_shape=(224,224,3),
alpha=1.0,
include_top=False,
weights="imagenet")
for layer in base_model.layers:
layer.trainable = False
model_transfered_1=Sequential()
model_transfered_1.add(base_model)
# Flattening
model_transfered_1.add(Flatten())
# Fully connected layer 1st layer
model_transfered_1.add(Dense(32))
model_transfered_1.add(BatchNormalization())
model_transfered_1.add(Activation('relu'))
model_transfered_1.add(Dropout(0.4))
# Fully connected layer 2nd layer
model_transfered_1.add(Dense(32))
model_transfered_1.add(BatchNormalization())
model_transfered_1.add(Activation('relu'))
model_transfered_1.add(Dropout(0.4))
model_transfered_1.add(Dense(7, activation='softmax'))
model_transfered_1.compile(optimizer=Adam(lr=0.0005),
loss='categorical_crossentropy', metrics=['categorical_accuracy'])
epochs = 10
steps_per_epoch = train_generator.n//train_generator.batch_size
validation_steps = validation_generator.n//validation_generator.batch_size
history = model_transfered_1.fit(
x=train_generator,
steps_per_epoch=steps_per_epoch,
epochs=epochs,
validation_data = validation_generator,
validation_steps = validation_steps,
shuffle=True
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment