Last active
May 17, 2020 10:29
-
-
Save quangnhat185/1fa0dd7b61b3eba39fa5043154db3451 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
# Create our model with pre-trained MobileNetV2 architecture from imagenet | |
def create_model(lr=1e-4,decay=1e-4/25, training=False,output_shape=y.shape[1]): | |
baseModel = MobileNetV2(weights="imagenet", | |
include_top=False, | |
input_tensor=Input(shape=(80, 80, 3))) | |
headModel = baseModel.output | |
headModel = AveragePooling2D(pool_size=(3, 3))(headModel) | |
headModel = Flatten(name="flatten")(headModel) | |
headModel = Dense(128, activation="relu")(headModel) | |
headModel = Dropout(0.5)(headModel) | |
headModel = Dense(output_shape, activation="softmax")(headModel) | |
model = Model(inputs=baseModel.input, outputs=headModel) | |
if training: | |
# define trainable lalyer | |
for layer in baseModel.layers: | |
layer.trainable = True | |
# compile model | |
optimizer = Adam(lr=lr, decay = decay) | |
model.compile(loss="categorical_crossentropy", optimizer=optimizer,metrics=["accuracy"]) | |
return model | |
# initilaize initial hyperparameter | |
INIT_LR = 1e-4 | |
EPOCHS = 30 | |
model = create_model(lr=INIT_LR, decay=INIT_LR/EPOCHS,training=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment