Initializer that generates tensors initialized to 0.
tf.compat.v1.keras.initializers.Zeros(
    dtype=tf.dtypes.float32
)
 Migrate to TF2
tf.compat.v1.zeros_initializer is compatible with eager execution and tf.function.
To migrate to TF2, please use tf.zerosinitializer instead. The dtype argument in <a href="../../../../../tf/compat/v1/keras/initializers/Zeros#init_">tf.compat.v1.zerosinitializer.init_() does not exist in tf.zerosinitializer.init_(). However, you can specify the dtype in __call__() in both cases.
Before:
initializer = tf.compat.v1.zeros_initializer(dtype=tf.float32) variable = tf.Variable(initializer(shape=[3, 3]))
After:
initializer = tf.zeros_initializer() variable = tf.Variable(initializer(shape=[3, 3], dtype=tf.float32))
| TF1 Arg Name | TF2 Arg Name | Note | 
|---|---|---|
| dtype | dtype | In __call__()method | 
| partition_info | - | ( __call__arg in TF1) Not supported | 
Before:
initializer = tf.compat.v1.zeros_initializer(dtype=tf.float32)
tf.Variable(initializer(shape=[3])).numpy()
array([0., 0., 0.], dtype=float32)
tf.Variable(initializer(shape=[3, 3])).numpy()
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]], dtype=float32)
initializer = tf.compat.v1.zeros_initializer()
tf.Variable(initializer(shape=[3], dtype=tf.float32)).numpy()
array([0., 0., 0.], dtype=float32)
tf.Variable(initializer(shape=[3, 3], dtype=tf.float32)).numpy()
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]], dtype=float32)
 After:
initializer = tf.zeros_initializer()
tf.Variable(initializer(shape=[3], dtype=tf.float32)).numpy()
array([0., 0., 0.], dtype=float32)
tf.Variable(initializer(shape=[3, 3], dtype=tf.float32)).numpy()
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]], dtype=float32)
  from_config
@classmethod
from_config(
    config
)
 Instantiates an initializer from a configuration dictionary.
initializer = RandomUniform(-1, 1) config = initializer.get_config() initializer = RandomUniform.from_config(config)
| Args | |
|---|---|
| config | A Python dictionary. It will typically be the output of get_config. | 
| Returns | |
|---|---|
| An Initializer instance. | 
get_configget_config()
Returns the configuration of the initializer as a JSON-serializable dict.
| Returns | |
|---|---|
| A JSON-serializable Python dict. | 
__call__
__call__(
    shape, dtype=None, partition_info=None
)
 Returns a tensor object initialized as specified by the initializer.
| Args | |
|---|---|
| shape | Shape of the tensor. | 
| dtype | Optional dtype of the tensor. If not provided use the initializer dtype. | 
| partition_info | Optional information about the possible partitioning of a tensor. | 
    © 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
    https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/compat/v1/keras/initializers/Zeros