As part of our migration to TensorFlow 2 I\'d like to enable TensorFlow v2 behaviour in TensorFlow v1 (specifically TensorFlow 1.14). I\'m aware that I can call tf.ena
That actually exists, if you set the environment variable TF2_BEHAVIOR
to 1
it will enable 2.x behavior. I have not found documentation about it, but you can see it in a comment in the source code:
# TF2 behavior is enabled if either 1) enable_v2_behavior() is called or
# 2) the TF2_BEHAVIOR=1 environment variable is set. In the latter case,
# the modules below independently check if tf2.enabled().
I tested it in 1.15.0 and it seems to work:
import os
os.environ['TF2_BEHAVIOR'] = '1'
import tensorflow as tf
print(tf.constant([1, 2, 3])) # Eager mode is enabled
# tf.Tensor([1 2 3], shape=(3,), dtype=int32)
print(tf.TensorShape([1, 2])[1]) # TensorShape dimensions are int
# 2