Created
June 24, 2022 17:54
-
-
Save SmiffyKMc/dbb7a402e00044d04b43cb85a5457234 to your computer and use it in GitHub Desktop.
MobileNet model
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
import tensorflow as tf | |
from tensorflow import keras | |
from keras import layers | |
conv_base = keras.applications.mobilenet_v2.MobileNetV2( | |
weights="imagenet", | |
include_top=False | |
) | |
conv_base.trainable = False | |
inputs = keras.Input(shape=(256, 256, 3)) | |
x = data_augmentation(inputs) | |
x = keras.applications.mobilenet_v2.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(2, activation=keras.activations.softmax)(x) | |
model = keras.Model(inputs, outputs) | |
model.compile(loss=keras.losses.SparseCategoricalCrossentropy(), | |
optimizer=keras.optimizers.RMSprop(), | |
metrics=["accuracy"]) | |
callbacks = [ | |
keras.callbacks.ModelCheckpoint( | |
filepath=f"{hotDogDir}hotdog_multiclassifier_mobilenet_v1.keras", | |
save_best_only=True, | |
monitor="val_loss" | |
) | |
] | |
history = model.fit( | |
train_dataset, | |
epochs=20, | |
validation_data=validation_dataset, | |
callbacks=callbacks | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment