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