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


Python models.clone_model方法代码示例

本文整理汇总了Python中keras.models.clone_model方法的典型用法代码示例。如果您正苦于以下问题:Python models.clone_model方法的具体用法?Python models.clone_model怎么用?Python models.clone_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在keras.models的用法示例。


在下文中一共展示了models.clone_model方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_model

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import clone_model [as 别名]
def load_model(filename=None, model=None, weights_file=None, custom_objects={}):
    """Loads model architecture from JSON and instantiates the model.
        filename: path to JSON file specifying model architecture
        model:    (or) a Keras model to be cloned
        weights_file: path to HDF5 file containing model weights
	custom_objects: A Dictionary of custom classes used in the model keyed by name"""
    import_keras()
    from keras.models import model_from_json, clone_model
    if filename is not None:
        with open( filename ) as arch_f:
            json_str = arch_f.readline()
            new_model = model_from_json( json_str, custom_objects=custom_objects) 
    if model is not None:
        new_model = clone_model(model)
    if weights_file is not None:
        new_model.load_weights( weights_file )
    return new_model 
开发者ID:vlimant,项目名称:mpi_learn,代码行数:19,代码来源:utils.py

示例2: clone_model

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import clone_model [as 别名]
def clone_model(self):
        model_copy = clone_model(self.model)
        model_copy.set_weights(self.model.get_weights())
        return model_copy 
开发者ID:kermitt2,项目名称:delft,代码行数:6,代码来源:models.py

示例3: fit

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import clone_model [as 别名]
def fit(self,
            latent_dim = 128,
            reg_latent = 0,
            layers = [512, 256, 128, 64],
            reg_layes = [0 ,0, 0, 0],
            learning_rate = 0.001,
            epochs = 30,
            batch_size = 256,
            num_negatives = 4,
            **earlystopping_kwargs):


        self.latent_dim = latent_dim
        self.reg_latent = reg_latent
        self.layers = layers
        self.reg_layes = reg_layes
        self.learning_rate = learning_rate
        self.epochs = epochs
        self.batch_size = batch_size
        self.num_negatives = num_negatives


        self._init_model()

        self._best_model = clone_model(self.model)
        self._best_model.set_weights(self.model.get_weights())

        self._train_with_early_stopping(epochs,
                                        algorithm_name = self.RECOMMENDER_NAME,
                                        **earlystopping_kwargs)

        print("MCRec_RecommenderWrapper: Tranining complete")

        self.model = clone_model(self._best_model)
        self.model.set_weights(self._best_model.get_weights()) 
开发者ID:MaurizioFD,项目名称:RecSys2019_DeepLearning_Evaluation,代码行数:37,代码来源:MCRecRecommenderWrapper.py

示例4: _update_best_model

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import clone_model [as 别名]
def _update_best_model(self):
        # Keras only clones the structure of the model, not the weights
        self._best_model = clone_model(self.model)
        self._best_model.set_weights(self.model.get_weights()) 
开发者ID:MaurizioFD,项目名称:RecSys2019_DeepLearning_Evaluation,代码行数:6,代码来源:MCRecRecommenderWrapper.py

示例5: deep_clone_model

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import clone_model [as 别名]
def deep_clone_model(source_model):

    destination_model = clone_model(source_model)
    destination_model.set_weights(source_model.get_weights())

    return destination_model 
开发者ID:MaurizioFD,项目名称:RecSys2019_DeepLearning_Evaluation,代码行数:8,代码来源:NeuMF_RecommenderWrapper.py

示例6: get_model

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import clone_model [as 别名]
def get_model(self):
        
        model = clone_model(self.model_copy)
        model.load_weights('./weights/sigma_estimation_model.hdf5')
        adam=Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0)
        model.compile(loss=fine_tuning_loss, optimizer=adam)
        
        return model 
开发者ID:csm9493,项目名称:FC-AIDE-Keras,代码行数:10,代码来源:sigma_est.py

示例7: __init__

# 需要导入模块: from keras import models [as 别名]
# 或者: from keras.models import clone_model [as 别名]
def __init__(self,
                 input_dim,
                 quantiles,
                 depth=3,
                 width=128,
                 activation="relu",
                 ensemble_size=1,
                 **kwargs):
        """
        Create a QRNN model.

        Arguments:

            input_dim(int): The dimension of the measurement space, i.e. the number
                            of elements in a single measurement vector y

            quantiles(np.array): 1D-array containing the quantiles  to estimate of
                                 the posterior distribution. Given as fractions
                                 within the range [0, 1].

            depth(int): The number of hidden layers  in the neural network to
                        use for the regression. Default is 3, i.e. three hidden
                        plus input and output layer.

            width(int): The number of neurons in each hidden layer.

            activation(str): The name of the activation functions to use. Default
                             is "relu", for rectified linear unit. See 
                             `this <https://keras.io/activations>`_ link for
                             available functions.

            **kwargs: Additional keyword arguments are passed to the constructor
                      call `keras.layers.Dense` of the hidden layers, which can
                      for example be used to add regularization. For more info consult
                      `Keras documentation. <https://keras.io/layers/core/#dense>`_
        """
        self.input_dim = input_dim
        self.quantiles = np.array(quantiles)
        self.depth = depth
        self.width = width
        self.activation = activation

        model = Sequential()
        if depth == 0:
            model.add(Dense(input_dim=input_dim,
                            units=len(quantiles),
                            activation=None))
        else:
            model.add(Dense(input_dim=input_dim,
                            units=width,
                            activation=activation))
            for i in range(depth - 2):
                model.add(Dense(units=width,
                                activation=activation,
                                **kwargs))
            model.add(Dense(units=len(quantiles), activation=None))
        self.models = [clone_model(model) for i in range(ensemble_size)] 
开发者ID:atmtools,项目名称:typhon,代码行数:59,代码来源:qrnn.py


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