當前位置: 首頁>>代碼示例>>Python>>正文


Python keras.optimizers方法代碼示例

本文整理匯總了Python中tensorflow.keras.optimizers方法的典型用法代碼示例。如果您正苦於以下問題:Python keras.optimizers方法的具體用法?Python keras.optimizers怎麽用?Python keras.optimizers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.keras的用法示例。


在下文中一共展示了keras.optimizers方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: init_optimizer

# 需要導入模塊: from tensorflow import keras [as 別名]
# 或者: from tensorflow.keras import optimizers [as 別名]
def init_optimizer(optimizer_string, logger=None, **kwargs):
    """
    Same as 'init_losses', but for optimizers.
    Please refer to the 'init_losses' docstring.
    """
    optimizer = _init(
        optimizer_string,
        tf_funcs=[optimizers, addon_optimizers],
        custom_funcs=None,
        logger=logger
    )[0]
    return optimizer(**kwargs) 
開發者ID:perslev,項目名稱:MultiPlanarUNet,代碼行數:14,代碼來源:utils.py

示例2: init_activation

# 需要導入模塊: from tensorflow import keras [as 別名]
# 或者: from tensorflow.keras import optimizers [as 別名]
def init_activation(activation_string, logger=None, **kwargs):
    """
    Same as 'init_losses', but for optimizers.
    Please refer to the 'init_losses' docstring.
    """
    activation = _init(
        activation_string,
        tf_funcs=[activations, addon_activations],
        custom_funcs=None,
        logger=logger
    )[0]
    return activation 
開發者ID:perslev,項目名稱:MultiPlanarUNet,代碼行數:14,代碼來源:utils.py

示例3: compile

# 需要導入模塊: from tensorflow import keras [as 別名]
# 或者: from tensorflow.keras import optimizers [as 別名]
def compile(self, model: Model, optimizer_name: str, loss_name: str,
                learning_rate: Optional[Union[float, List[float]]],
                learning_rate_decay: Optional[Union[float, str]]) -> Model:
        """
        Compile model with given optimizer and loss

        Args:
            model: keras uncompiled model
            optimizer_name: name of optimizer from keras.optimizers
            loss_name: loss function name (from keras.losses)
            learning_rate: learning rate.
            learning_rate_decay: learning rate decay.

        Returns:

        """
        optimizer_func = getattr(tensorflow.keras.optimizers, optimizer_name, None)
        if callable(optimizer_func):
            if isinstance(learning_rate, float) and isinstance(learning_rate_decay, float):
                # in this case decay will be either given in config or, by default, learning_rate_decay=0.
                self.optimizer = optimizer_func(lr=learning_rate, decay=learning_rate_decay)
            else:
                self.optimizer = optimizer_func()
        else:
            raise AttributeError("Optimizer {} is not defined in `tensorflow.keras.optimizers`".format(optimizer_name))

        loss_func = getattr(tensorflow.keras.losses, loss_name, None)
        if callable(loss_func):
            loss = loss_func
        else:
            raise AttributeError("Loss {} is not defined".format(loss_name))

        model.compile(optimizer=self.optimizer,
                      loss=loss)
        return model 
開發者ID:deepmipt,項目名稱:DeepPavlov,代碼行數:37,代碼來源:keras_classification_model.py


注:本文中的tensorflow.keras.optimizers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。