Last active
February 11, 2019 02:26
-
-
Save lsimmons2/6bbc44256247f127a47398aa313c41dc 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
from tensorflow.python.keras.models import Model | |
from tensorflow.python.keras.applications import ResNet50 | |
from tensorflow.python.keras.layers import Dense | |
import config | |
def get_age_model(): | |
# adapted from https://github.com/yu4u/age-gender-estimation/blob/master/age_estimation/model.py | |
age_model = ResNet50( | |
include_top=False, | |
weights='imagenet', | |
input_shape=(config.RESNET50_DEFAULT_IMG_WIDTH, config.RESNET50_DEFAULT_IMG_WIDTH, 3), | |
pooling='avg') | |
prediction = Dense(units=101, | |
kernel_initializer='he_normal', | |
use_bias=False, | |
activation='softmax', | |
name='pred_age')(age_model.output) | |
age_model = Model(inputs=age_model.input, outputs=prediction) | |
age_model.load_weights(config.AGE_TRAINED_WEIGHTS_FILE) | |
print 'Loaded weights from age classifier' | |
return age_model | |
def get_model(): | |
base_model = get_age_model() | |
last_hidden_layer = base_model.get_layer(index=-2) | |
base_model = Model( | |
inputs=base_model.input, | |
outputs=last_hidden_layer.output) | |
prediction = Dense(1, kernel_initializer='normal')(base_model.output) | |
model = Model(inputs=base_model.input, outputs=prediction) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment