Created
March 6, 2021 18:12
-
-
Save AyishaR/4db9fd46e96cd0be6088d9630a6f0280 to your computer and use it in GitHub Desktop.
This file contains 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
base_model = keras.applications.DenseNet121(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(len(class_names), activation = 'softmax')(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=losses.CategoricalCrossentropy(), optimizer=optimizers.Adam(0.01), metrics=['accuracy']) | |
history = model.fit(train_ds, validation_data = test_ds, epochs=256, callbacks = cb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment