# tf.compat.v1.keras.initializers.Zeros

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/init_ops.py#L97-L179) |

Initializer that generates tensors initialized to 0.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.initializers.zeros`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/zeros_initializer), \`tf.compat.v1.keras.initializers.zeros\`, [`tf.compat.v1.zeros_initializer`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/zeros_initializer)

<br />

    tf.compat.v1.keras.initializers.Zeros(
        dtype=https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/dtypes#float32
    )

<br />

## Migrate to TF2

<br />

> [!CAUTION]
> **Caution:** This API was designed for TensorFlow v1. Continue reading for details on how to migrate from this API to a native TensorFlow v2 equivalent. See the [TensorFlow v1 to TensorFlow v2 migration guide](https://www.tensorflow.org/guide/migrate) for instructions on how to migrate the rest of your code.

[`tf.compat.v1.zeros_initializer`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/compat/v1/keras/initializers/Zeros) is compatible with eager execution
and [`tf.function`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/function).

To migrate to TF2, please use [`tf.zerosinitializer`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/zeros_initializer)*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_()`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/zeros_initializer#__init__). However, you can specify the `dtype` in
`__call__()` in both cases.

#### Structural Mapping to TF2

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))

#### How to Map Arguments

| TF1 Arg Name | TF2 Arg Name | Note |
|---|---|---|
| `dtype` | `dtype` | In `__call__()` method |
| `partition_info` | - | (`__call__` arg in TF1) Not supported |

#### Before \& After Usage Example

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)

<br />

<br />

## Description

## Methods

### `from_config`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/init_ops.py#L75-L94)

    @classmethod
    from_config(
        config
    )

Instantiates an initializer from a configuration dictionary.

#### Example:

    initializer = RandomUniform(-1, 1)
    config = initializer.get_config()
    initializer = RandomUniform.from_config(config)

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | A Python dictionary. It will typically be the output of `get_config`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An Initializer instance. ||

<br />

### `get_config`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/init_ops.py#L178-L179)

    get_config()

Returns the configuration of the initializer as a JSON-serializable dict.

<br />

<br />

<br />

| Returns ||
|---|---|
| A JSON-serializable Python dict. ||

<br />

### `__call__`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/init_ops.py#L173-L176)

    __call__(
        shape, dtype=None, partition_info=None
    )

Returns a tensor object initialized as specified by the initializer.

<br />

<br />

<br />

| 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. |

<br />