tf.compat.v1.assign

Update ref by assigning value to it.

Migrate to TF2

tf.compat.v1.assign is mostly compatible with eager execution and tf.function. However, argument 'validate_shape' will be ignored. To avoid shape validation, set 'shape' to tf.TensorShape(None) when constructing the variable:

import tensorflow as tf
a = tf.Variable([1], shape=tf.TensorShape(None))
tf.compat.v1.assign(a, [2,3])

To switch to the native TF2 style, one could use method 'assign' of tf.Variable:

How to Map Arguments

TF1 Arg Name TF2 Arg Name Note
ref self In assign() method
value value In assign() method
validate_shape Not supported Specify shape in the constructor to replicate behavior
use_locking use_locking In assign() method
name name In assign() method
- read_value Set to True to replicate behavior (True is default)