本文整理汇总了Python中tensorflow.python.keras.models.load_model方法的典型用法代码示例。如果您正苦于以下问题:Python models.load_model方法的具体用法?Python models.load_model怎么用?Python models.load_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.keras.models
的用法示例。
在下文中一共展示了models.load_model方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def __init__(self, model_name='fcn'):
"""
Initializes this classifier with a Keras model.
:param model_name: model name from sub-package models. E.g. 'fma2018-meter'.
"""
self._to_meter = lambda index: index + 2
self.model_name = model_name
# mazurka and deeptemp/shallowtempo models use a different kind of normalization
self.normalize = std_normalizer if 'dt_maz_v' in self.model_name \
or 'deeptemp' in self.model_name \
or 'deepsquare' in self.model_name \
or 'shallowtemp' in self.model_name \
else max_normalizer
resource = _to_model_resource(model_name)
try:
file = _extract_from_package(resource)
except Exception as e:
print('Failed to find a model named \'{}\'. Please check the model name.'.format(model_name),
file=sys.stderr)
raise e
try:
self.model = load_model(file)
finally:
os.remove(file)
示例2: loadFullModel
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def loadFullModel(self, prediction_speed="normal", num_objects=10):
"""
'loadFullModel()' function is used to load the model structure into the program from the file path defined
in the setModelPath() function. As opposed to the 'loadModel()' function, you don't need to specify the model type. This means you can load any Keras model trained with or without ImageAI and perform image prediction.
- prediction_speed (optional), Acceptable values are "normal", "fast", "faster" and "fastest"
- num_objects (required), the number of objects the model is trained to recognize
:param prediction_speed:
:param num_objects:
:return:
"""
self.numObjects = num_objects
if (prediction_speed == "normal"):
self.__input_image_size = 224
elif (prediction_speed == "fast"):
self.__input_image_size = 160
elif (prediction_speed == "faster"):
self.__input_image_size = 120
elif (prediction_speed == "fastest"):
self.__input_image_size = 100
if (self.__modelLoaded == False):
image_input = Input(shape=(self.__input_image_size, self.__input_image_size, 3))
model = load_model(filepath=self.modelPath)
self.__model_collection.append(model)
self.__modelLoaded = True
self.__modelType = "full"
示例3: load_model
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def load_model():
global graph
graph = tf.get_default_graph()
global model
model = VGG16(weights='imagenet',
input_shape=input_shape,
pooling='max',
include_top=False)
示例4: load_best_model
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def load_best_model():
from tensorflow.python.keras.models import load_model
model = load_model(model_all, custom_objects={'loss_function': dice_coef_loss})
return model
示例5: load_checkpoint
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def load_checkpoint(self, path):
# See https://stackoverflow.com/a/42763323
del self.model
self.model = load_model(path)
示例6: load
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def load(self, file_path):
return load_model(file_path)
示例7: _patch_io_calls
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def _patch_io_calls(Network, Sequential, keras_saving):
try:
if Sequential is not None:
Sequential._updated_config = _patched_call(Sequential._updated_config,
PatchKerasModelIO._updated_config)
if hasattr(Sequential.from_config, '__func__'):
# noinspection PyUnresolvedReferences
Sequential.from_config = classmethod(_patched_call(Sequential.from_config.__func__,
PatchKerasModelIO._from_config))
else:
Sequential.from_config = _patched_call(Sequential.from_config, PatchKerasModelIO._from_config)
if Network is not None:
Network._updated_config = _patched_call(Network._updated_config, PatchKerasModelIO._updated_config)
if hasattr(Sequential.from_config, '__func__'):
# noinspection PyUnresolvedReferences
Network.from_config = classmethod(_patched_call(Network.from_config.__func__,
PatchKerasModelIO._from_config))
else:
Network.from_config = _patched_call(Network.from_config, PatchKerasModelIO._from_config)
Network.save = _patched_call(Network.save, PatchKerasModelIO._save)
Network.save_weights = _patched_call(Network.save_weights, PatchKerasModelIO._save_weights)
Network.load_weights = _patched_call(Network.load_weights, PatchKerasModelIO._load_weights)
if keras_saving is not None:
keras_saving.save_model = _patched_call(keras_saving.save_model, PatchKerasModelIO._save_model)
keras_saving.load_model = _patched_call(keras_saving.load_model, PatchKerasModelIO._load_model)
except Exception as ex:
LoggerRoot.get_base_logger(TensorflowBinding).warning(str(ex))
示例8: load_model_from_disk
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def load_model_from_disk(path_to_model_on_disk, compile=True):
""" Load weights from disk and add to model """
logging.info("Loading model from: %s" % path_to_model_on_disk)
loaded_model = load_model(
path_to_model_on_disk,
compile=compile,
custom_objects={
'accuracy': accuracy,
'top_k_accuracy': top_k_accuracy,
'masked_loss_function':
build_masked_loss(K.sparse_categorical_crossentropy)})
return loaded_model
示例9: check_model
# 需要导入模块: from tensorflow.python.keras import models [as 别名]
# 或者: from tensorflow.python.keras.models import load_model [as 别名]
def check_model(model, model_name, x, y, check_model_io=True):
"""
compile model,train and evaluate it,then save/load weight and model file.
:param model:
:param model_name:
:param x:
:param y:
:param check_model_io: test save/load model file or not
:return:
"""
model.compile('adam', 'binary_crossentropy',
metrics=['binary_crossentropy'])
model.fit(x, y, batch_size=100, epochs=1, validation_split=0.5)
print(model_name + " test train valid pass!")
model.save_weights(model_name + '_weights.h5')
model.load_weights(model_name + '_weights.h5')
os.remove(model_name + '_weights.h5')
print(model_name + " test save load weight pass!")
if check_model_io:
save_model(model, model_name + '.h5')
model = load_model(model_name + '.h5', custom_objects)
os.remove(model_name + '.h5')
print(model_name + " test save load model pass!")
print(model_name + " test pass!")