def load_keras_model(weights, yaml=None, json=None,
normalise_conv_for_one_hot_encoded_input=False,
axis_of_normalisation=None,
name_of_conv_layer_to_normalise=None):
if (normalise_conv_for_one_hot_encoded_input):
assert axis_of_normalisation is not None,\
"specify axis of normalisation for normalising one-hot encoded input"
assert yaml is not None or json is not None,\
"either yaml or json must be specified"
assert yaml is None or json is None,\
"only one of yaml or json must be specified"
if (yaml is not None):
from keras.models import model_from_yaml
model = model_from_yaml(open(yaml).read())
else:
from keras.models import model_from_json
model = model_from_json(open(json).read())
model.load_weights(weights)
if (normalise_conv_for_one_hot_encoded_input):
mean_normalise_first_conv_layer_weights(
model,
axis_of_normalisation=axis_of_normalisation,
name_of_conv_layer_to_normalise=name_of_conv_layer_to_normalise)
return model
评论列表
文章目录