Skip to content

Instantly share code, notes, and snippets.

@AyishaR
Created January 5, 2021 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AyishaR/4e20590f02e17ec240d1253f20a6c467 to your computer and use it in GitHub Desktop.
Save AyishaR/4e20590f02e17ec240d1253f20a6c467 to your computer and use it in GitHub Desktop.
base_model = keras.applications.InceptionV3(weights='imagenet', input_shape=input_shape, include_top=False) # False, do not include the classification layer of the model
base_model.trainable = False
inputs = tf.keras.Input(shape=input_shape)
x = base_model(inputs, training=False)
x = keras.layers.GlobalAveragePooling2D()(x)
outputs = keras.layers.Dense(1, activation = 'sigmoid')(x) # Add own classififcation layer
model = keras.Model(inputs, outputs)
cb = [callbacks.EarlyStopping(monitor = 'val_loss', patience = 5, restore_best_weights = True)]
model.compile(loss='binary_crossentropy', optimizer=optimizers.Adam(0.1), metrics=['accuracy'])
history = model.fit(train_ds, validation_data = val_ds, epochs=32, callbacks = cb)
model.compile(loss='binary_crossentropy', optimizer=optimizers.Adam(0.01), metrics=['accuracy'])
history1 = model.fit(train_ds, validation_data = val_ds, epochs=32, callbacks = cb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment