Created
May 7, 2020 14:13
-
-
Save sayakpaul/e8605ee385527a8c973c7b4cb8de79cd 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
# Load the MobileNetV2 model but exclude the classification layers | |
EXTRACTOR = MobileNetV2(weights="imagenet", include_top=False, | |
input_shape=(224, 224, 3)) | |
# We will set it to both True and False | |
EXTRACTOR.trainable = True | |
# Construct the head of the model that will be placed on top of the | |
# the base model | |
class_head = EXTRACTOR.output | |
class_head = GlobalAveragePooling2D()(class_head) | |
class_head = Dense(512, activation="relu")(class_head) | |
class_head = Dropout(0.5)(class_head) | |
class_head = Dense(5, activation="softmax")(class_head) | |
# Create the new model | |
classifier = Model(inputs=EXTRACTOR.input, outputs=class_head) | |
# Compile and return the model | |
classifier.compile(loss="sparse_categorical_crossentropy", | |
optimizer="adam", | |
metrics=["accuracy"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment