<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/random_initializers.py#L201-L329) |

Initializer that adapts its scale to the shape of its input tensors.

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

#### View aliases


**Main aliases**

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

<br />

    tf.keras.initializers.VarianceScaling(
        scale=1.0,
        mode='fan_in',
        distribution='truncated_normal',
        seed=None,
        input_axes=None,
        output_axes=None
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Train a Deep Q Network with TF-Agents](https://www.tensorflow.org/agents/tutorials/1_dqn_tutorial) - [Networks](https://www.tensorflow.org/agents/tutorials/8_networks_tutorial) |

With `distribution="truncated_normal" or "untruncated_normal"`, samples are
drawn from a truncated/untruncated normal distribution with a mean of zero
and a standard deviation (after truncation, if used) `stddev = sqrt(scale /
n)`, where `n` is:

- number of input units in the weight tensor, if `mode="fan_in"`
- number of output units, if `mode="fan_out"`
- average of the numbers of input and output units, if `mode="fan_avg"`

With `distribution="uniform"`, samples are drawn from a uniform distribution
within `[-limit, limit]`, where `limit = sqrt(3 * scale / n)`.

#### Examples:

    # Standalone usage:
    initializer = VarianceScaling(
        scale=0.1, mode='fan_in', distribution='uniform')
    values = initializer(shape=(2, 2))

    # Usage in a Keras layer:
    initializer = VarianceScaling(
        scale=0.1, mode='fan_in', distribution='uniform')
    layer = Dense(3, kernel_initializer=initializer)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `scale` | Scaling factor (positive float). |
| `mode` | One of `"fan_in"`, `"fan_out"`, `"fan_avg"`. |
| `distribution` | Random distribution to use. One of `"truncated_normal"`, `"untruncated_normal"`, or `"uniform"`. |
| `seed` | A Python integer or instance of `keras.backend.SeedGenerator`. Used to make the behavior of the initializer deterministic. Note that an initializer seeded with an integer or `None` (unseeded) will produce the same random values across multiple calls. To get different random values across multiple calls, use as seed an instance of `keras.backend.SeedGenerator`. |
| `input_axes` | Optional list of integers. The axes of the input tensor that should be considered for computing the fan-in. |
| `output_axes` | Optional list of integers. The axes of the output tensor that should be considered for computing the fan-out. |

<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/initializer.py#L76-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, 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/random_initializers.py#L320-L329)

    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/random_initializers.py#L293-L318)

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