Created
November 1, 2018 10:30
-
-
Save malnakli/ea3769b364a2e6e2e0db819c17f6893a to your computer and use it in GitHub Desktop.
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
from keras.applications.mobilenetv2 import MobileNetV2 | |
from keras.layers import Dense, Input, Dropout | |
from keras.models import Model | |
def build_model( ): | |
input_tensor = Input(shape=(target_size, target_size, 3)) | |
base_model = MobileNetV2( | |
include_top=False, | |
weights='imagenet', | |
input_tensor=input_tensor, | |
input_shape=(target_size, target_size, 3), | |
pooling='avg') | |
for layer in base_model.layers: | |
layer.trainable = True # trainable has to be false in order to freeze the layers | |
op = Dense(256, activation='relu')(base_model.output) | |
op = Dropout(.25)(op) | |
## | |
# softmax: calculates a probability for every possible class. | |
# | |
# activation='softmax': return the highest probability; | |
# for example, if 'Coat' is the highest probability then the result would be | |
# something like [0,0,0,0,1,0,0,0,0,0] with 1 in index 5 indicate 'Coat' in our case. | |
## | |
output_tensor = Dense(10, activation='softmax')(op) | |
model = Model(inputs=input_tensor, outputs=output_tensor) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment