当前位置: 首页>>代码示例>>Python>>正文


Python models.load_model方法代码示例

本文整理汇总了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) 
开发者ID:hendriks73,项目名称:tempo-cnn,代码行数:27,代码来源:classifier.py

示例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" 
开发者ID:OlafenwaMoses,项目名称:ImageAI,代码行数:34,代码来源:__init__.py

示例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) 
开发者ID:milvus-io,项目名称:bootcamp,代码行数:11,代码来源:app.py

示例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 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:6,代码来源:3D_VResFCN_Upsampling_final_Motion_Shim_Multi_Label.py

示例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) 
开发者ID:ray-project,项目名称:ray,代码行数:6,代码来源:pbt_tune_cifar10_with_keras.py

示例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) 
开发者ID:d909b,项目名称:cxplain,代码行数:4,代码来源:tf_model_serialisation.py

示例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)) 
开发者ID:allegroai,项目名称:trains,代码行数:31,代码来源:tensorflow_bind.py

示例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 
开发者ID:marco-willi,项目名称:camera-trap-classifier,代码行数:14,代码来源:prepare_model.py

示例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!") 
开发者ID:shenweichen,项目名称:DeepCTR,代码行数:29,代码来源:utils.py


注:本文中的tensorflow.python.keras.models.load_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。