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


Python keras.activations方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from tensorflow import keras [as 別名]
# 或者: from tensorflow.keras import activations [as 別名]
def __init__(self,
                 deg=1,
                 output_units=1,
                 use_xbias=True,
                 init_w=None,
                 name=None,
                 activation=None,
                 kernel_regularizer=None,
                 kernel_constraint=None):
        super().__init__(name=name)
        self.input_spec = InputSpec(min_ndim=2)
        self.deg = deg
        self.output_units = output_units
        self.use_bias = use_xbias
        self.activation = activations.get(activation)
        self.kernel_regularizer = tfk.regularizers.get(kernel_regularizer)
        self.kernel_constraint = tfk.constraints.get(kernel_constraint)
        self.init_w = init_w

        if self.init_w is not None and len(self.init_w) != self.deg + 1:
            raise ValueError(f"If you specify initial weight for {self.deg}-deg polynomial, "
                             f"you must provide {self.deg + 1} weights") 
開發者ID:henrysky,項目名稱:astroNN,代碼行數:24,代碼來源:layers.py

示例2: get_config

# 需要導入模塊: from tensorflow import keras [as 別名]
# 或者: from tensorflow.keras import activations [as 別名]
def get_config(self):
        """
        :return: Dictionary of configuration
        :rtype: dict
        """
        config = {'degree': self.deg,
                  'use_bias': self.use_bias,
                  'activation': activations.serialize(self.activation),
                  'initial_weights': self.init_w,
                  'kernel_regularizer': tfk.regularizers.serialize(self.kernel_regularizer),
                  'kernel_constraint': tfk.constraints.serialize(self.kernel_constraint)}
        base_config = super().get_config()
        return {**dict(base_config.items()), **config} 
開發者ID:henrysky,項目名稱:astroNN,代碼行數:15,代碼來源:layers.py

示例3: __init__

# 需要導入模塊: from tensorflow import keras [as 別名]
# 或者: from tensorflow.keras import activations [as 別名]
def __init__(
        self,
        input_res,
        min_res,
        kernel_size,
        initial_filters,
        filters_cap,
        channels,  # number of classes
        use_dropout_encoder=True,
        use_dropout_decoder=True,
        dropout_prob=0.3,
        encoder_non_linearity=keras.layers.LeakyReLU,
        decoder_non_linearity=keras.layers.ReLU,
        use_attention=False,
    ):
        """Build the Semantic UNet model."""
        super().__init__(
            input_res,
            min_res,
            kernel_size,
            initial_filters,
            filters_cap,
            channels,
            use_dropout_encoder,
            use_dropout_decoder,
            dropout_prob,
            encoder_non_linearity,
            decoder_non_linearity,
            last_activation=keras.activations.softmax,
            use_attention=use_attention,
        ) 
開發者ID:zurutech,項目名稱:ashpy,代碼行數:33,代碼來源:unet.py

示例4: init_activation

# 需要導入模塊: from tensorflow import keras [as 別名]
# 或者: from tensorflow.keras import activations [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

示例5: activation_factory

# 需要導入模塊: from tensorflow import keras [as 別名]
# 或者: from tensorflow.keras import activations [as 別名]
def activation_factory(activation_or_name_with_params: Union[dict, str, type]
                       ) -> Union[Callable[[tf.Tensor], tf.Tensor], partial]:
    """
    Factory to get the activation function

    Parameters
    ----------
    activation_or_name_with_params
        either activation fn itself, then will be returned as is, or only the
        name of activation, which will be get from tf.nn or from
        keras.activations modules or a dict with name and kwargs to pass
        to the activation_fn

    Returns
    -------
    activation_fn
        activation function

    """
    if callable(activation_or_name_with_params):
        return activation_or_name_with_params

    if activation_or_name_with_params is None:
        return tf.identity

    name_with_params = activation_or_name_with_params
    name, params = _get_name_and_params(name_with_params)

    if _check_should_import_function(name):
        activation_function = _import_function(name, params)
        _check_signature(activation_function, [], 1)
        return activation_function

    assert hasattr(tf.nn, name) or hasattr(keras.activations, name), (
        "Use activation name from tf.nn or keras.activations "
        "(got {})".format(name))

    if hasattr(tf.nn, name):
        activation = getattr(tf.nn, name)
    else:
        activation = getattr(keras.activations, name)

    if not params:
        return activation
    return partial(activation, **params) 
開發者ID:audi,項目名稱:nucleus7,代碼行數:47,代碼來源:tf_objects_factory.py


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