# tf.compat.v1.ones_initializer

<br />

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

Initializer that generates tensors initialized to 1.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.initializers.ones`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/ones_initializer)

<br />

    tf.compat.v1.ones_initializer(
        dtype=https://www.tensorflow.org/versions/r2.14/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.

This API is compatible with TF2 behavior and [`tf.function`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/function), and can be
migrated immediately with [`tf.keras.initializers.ones`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/keras/initializers/Ones).

Before:

    >>> initializer = tf.compat.v1.keras.initializers.ones()
    >>> initializer((1, 1))
    <tf.Tensor: shape=(1, 1), dtype=float32, numpy=array([[1.]], dtype=float32)>

After:

    >>> initializer = tf.keras.initializers.ones()
    >>> initializer((1, 1))
    <tf.Tensor: shape=(1, 1), dtype=float32, numpy=array([[1.]], dtype=float32)>

<br />

<br />

## Description

## Methods

### `from_config`

[View source](https://github.com/tensorflow/tensorflow/blob/v2.14.0/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.14.0/tensorflow/python/ops/init_ops.py#L215-L216)

    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.14.0/tensorflow/python/ops/init_ops.py#L210-L213)

    __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 />