<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/lookup_ops.py#L67-L108) |

Returns an Op that initializes all tables of the default graph.

#### View aliases


**Compat aliases for migration**

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

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

<br />

    tf.compat.v1.tables_initializer(
        name='init_all_tables'
    )

<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.tables_initializer`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/tables_initializer) is no longer needed with eager execution and
[`tf.function`](https://www.tensorflow.org/api_docs/python/tf/function). In TF2, when creating an initializable table like a
[`tf.lookup.StaticHashTable`](https://www.tensorflow.org/api_docs/python/tf/lookup/StaticHashTable), the table will automatically be initialized on
creation.

#### Before \& After Usage Example

Before:

    with tf.compat.v1.Session():
      init = tf.compat.v1.lookup.KeyValueTensorInitializer(['a', 'b'], [1, 2])
      table = tf.compat.v1.lookup.StaticHashTable(init, default_value=-1)
      tf.compat.v1.tables_initializer().run()
      result = table.lookup(tf.constant(['a', 'c'])).eval()
    result
    array([ 1, -1], dtype=int32)

After:

    init = tf.lookup.KeyValueTensorInitializer(['a', 'b'], [1, 2])
    table = tf.lookup.StaticHashTable(init, default_value=-1)
    table.lookup(tf.constant(['a', 'c'])).numpy()
    array([ 1, -1], dtype=int32)

<br />

<br />

## Description

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Universal Sentence Encoder-Lite demo](https://www.tensorflow.org/hub/tutorials/semantic_similarity_with_tf_hub_universal_encoder_lite) - [Generating Images with BigBiGAN](https://www.tensorflow.org/hub/tutorials/bigbigan_with_tf_hub) - [Classify Flowers with Transfer Learning](https://www.tensorflow.org/hub/tutorials/image_feature_vector) - [Wiki40B Language Models](https://www.tensorflow.org/hub/tutorials/wiki40b_lm) |

<br />

<br />

<br />

| ## Args ||
|---|---|
| `name` | Optional name for the initialization op. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| An Op that initializes all tables. Note that if there are not tables the returned Op is a NoOp. ||

<br />