get_initializer

Function

Obtains the initialization operator (Operation) of tensorflow.data.Iterator. This operator needs to use sess.run () to initialize Iterator.

Prototype

1
2
from mx_rec.util.initialize import ConfigInitializer
ConfigInitializer.get_instance().train_params_config.get_initializer(is_training)

Parameters

Parameter

Type

Mandatory/Optional

Description

is_training

bool

Mandatory

Whether the training mode is enabled.

  • True: training mode (train).
  • False: evaluation mode (eval).

Return Value

  • Success: TensorFlow operator (tf.Operation) for initializing the iterator
  • Failure: An exception is thrown.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import tensorflow as tf
from mx_rec.util.initialize import ConfigInitializer
from mx_rec.graph.modifier import modify_graph_and_start_emb_cache
# In train mode, automatic graph modification needs to be enabled.
# In train mode, automatic graph modification must be performed after gradient calculation.
# Calculate the gradient.
modify_graph_and_start_emb_cache(dump_graph=True)
with tf.compat.v1.Session() as sess:
  # Ensure that the modify_graph_and_start_emb_cache() API has been called.
    initializer = ConfigInitializer.get_instance().train_params_config.get_initializer(True)
    sess.run(initializer)

See Also

For details about the API call sequence and example, see Automatic Graph Modification.