當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。