本文整理汇总了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")
示例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}
示例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,
)
示例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
示例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)