Created
June 17, 2022 16:50
-
-
Save SmiffyKMc/b936a379617cc42afa98cd6582a44168 to your computer and use it in GitHub Desktop.
Freezed layers for our CNN
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
conv_base = keras.applications.vgg16.VGG16( | |
weights="imagenet", | |
include_top=False | |
) | |
conv_base.trainable = False | |
inputs = keras.Input(shape=(256, 256, 3)) | |
x = data_augmentation(inputs) | |
x = keras.applications.vgg16.preprocess_input(x) | |
x = conv_base(x) | |
x = layers.Flatten()(x) | |
x = layers.Dense(512)(x) | |
x = layers.Dropout(0.5)(x) | |
outputs = layers.Dense(1, activation=keras.activations.sigmoid)(x) | |
model = keras.Model(inputs, outputs) | |
model.compile(loss=keras.losses.BinaryCrossentropy(), | |
optimizer=keras.optimizers.RMSprop(), | |
metrics=["accuracy"]) | |
callbacks = [ | |
keras.callbacks.ModelCheckpoint( | |
filepath=f"{hotDogDir}hotdog_classifier_v4.keras", | |
save_best_only=True, | |
monitor="val_loss" | |
) | |
] | |
history = model.fit( | |
train_dataset, | |
epochs=50, | |
validation_data=validation_dataset, | |
callbacks=callbacks | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment