TensorFlow tf.keras.activations.deserialize

deserialize method of TensorFlow tf.keras.activations module returns activation function for a given string identifier.

Syntax

  

tf.keras.activations.deserialize(
  name, custom_objects=None
)
     

Parameters

name: (Required) The name of the activation function.

custom_objects: (Optional) {function_name: function_obj} dictionary listing user-provided activation functions.

Errors

ValueError: tf.keras.activations.deserialize raises Unknown activation function if the input string does not denote any defined Tensorflow activation function.

Examples

sigmoid function using deserialize method
   
import tensorflow as tf

sigmoid_func = tf.keras.activations.deserialize('sigmoid')

print(help(sigmoid_func))
     
Output
   
Help on function sigmoid in module keras.activations:

sigmoid(x)
  Sigmoid activation function, `sigmoid(x) = 1 / (1 + exp(-x))`.

  Applies the sigmoid activation function. For small values (<-5),
  `sigmoid` returns a value close to zero, and for large values (>5)
  the result of the function gets close to 1.

  Sigmoid is equivalent to a 2-element Softmax, where the second element is
  assumed to be zero. The sigmoid function always returns a value between
  0 and 1.

  For example:

  >>> a = tf.constant([-20, -1.0, 0.0, 1.0, 20], dtype = tf.float32)
  >>> b = tf.keras.activations.sigmoid(a)
  >>> b.numpy()
  array([2.0611537e-09, 2.6894143e-01, 5.0000000e-01, 7.3105860e-01,
            1.0000000e+00], dtype=float32)

  Args:
      x: Input tensor.

  Returns:
      Tensor with the sigmoid activation: `1 / (1 + exp(-x))`.
     
linear function using deserialize method
   
import tensorflow as tf

linear_func = tf.keras.activations.deserialize('linear')

print(help(linear_func))
     
Output
   
Help on function linear in module keras.activations:

linear(x)
  Linear activation function (pass-through).

  For example:

  >>> a = tf.constant([-3.0,-1.0, 0.0,1.0,3.0], dtype = tf.float32)
  >>> b = tf.keras.activations.linear(a)
  >>> b.numpy()
  array([-3., -1.,  0.,  1.,  3.], dtype=float32)

  Args:
      x: Input tensor.

  Returns:
      The input, unmodified.
     


Category: TensorFlow