<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/constant_initializers.py#L9-L46) |

Initializer that generates tensors with constant values.

Inherits From: [`Initializer`](https://www.tensorflow.org/api_docs/python/tf/keras/Initializer)

#### View aliases


**Main aliases**

[`tf.keras.initializers.constant`](https://www.tensorflow.org/api_docs/python/tf/keras/initializers/Constant)

<br />

    tf.keras.initializers.Constant(
        value=0.0
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Basic training loops](https://www.tensorflow.org/guide/basic_training_loops) | - [Classification on imbalanced data](https://www.tensorflow.org/tutorials/structured_data/imbalanced_data) - [Train a Deep Q Network with TF-Agents](https://www.tensorflow.org/agents/tutorials/1_dqn_tutorial) |

Only scalar values are allowed.
The constant value provided must be convertible to the dtype requested
when calling the initializer.

#### Examples:

    # Standalone usage:
    initializer = Constant(10.)
    values = initializer(shape=(2, 2))

    # Usage in a Keras layer:
    initializer = Constant(10.)
    layer = Dense(3, kernel_initializer=initializer)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `value` | A Python scalar. |

<br />

## Methods

### `clone`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/initializer.py#L96-L97)

    clone()

### `from_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/constant_initializers.py#L43-L46)

    @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, the output of `get_config()`. |

<br />

<br />

<br />

<br />

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

<br />

### `get_config`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/constant_initializers.py#L40-L41)

    get_config()

Returns the initializer's configuration as a JSON-serializable dict.

<br />

<br />

<br />

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

<br />

### `__call__`

[View source](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/initializers/constant_initializers.py#L34-L38)

    __call__(
        shape, dtype=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. |

<br />