Last active
December 1, 2018 18:49
-
-
Save RodrigoCMoraes/d76890fb8149182e2522014f308660ae to your computer and use it in GitHub Desktop.
Read keras model from architecture and weights file, json and h5 respectively
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
# https://gist.github.com/RodrigoCMoraes/d76890fb8149182e2522014f308660ae | |
import keras | |
def read_model(arch_file, weights_file, optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy']): | |
"""Read custom keras model from files | |
Args: | |
arch_file(str): json file with model architecture | |
weights_file(str): h5 file with weights of model | |
Returns: | |
model: model read from file | |
""" | |
with open(arch_file) as fl: | |
model = keras.models.model_from_json(fl.read()) | |
model.load_weights(weights_file, by_name=False) | |
model.compile(optimizer=optimizer, loss=loss, metrics=metrics) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting.