How to use TF2 instead of TF1

Hi, I would like to use tensorlflow 2 instead of 1. There is an error in the #Test cell.
TF1 is standard using graphical execution instead of the eager execution in TF2.
Anyone an idea how to address this issue?

Yes, I did it!!! (Sorry, bit proud of myself).
Change the #Test as follows:
with tf.compat.v1.Session() as sess:
print(“Test example:\n”)
y_true = tf.constant(np.array(
[[1, 1, 1],
[1, 1, 0],
[0, 1, 0],
[1, 0, 1]]
), dtype=tf.float64)

Add this to util.py:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()

1 Like

You might want to mention the handful of package and name changes, too. Replacing _keras_shape with just shape, for example. In Week 3 you’ll find Layer names changed. Deconvolution3D became Conv3DTranspose. keras.optimizers and keras.utils packaging changed. Other than those, the change you suggest is the simplest way to run the existing notebooks under TF2. Otherwise you have to make more extensive changes to make them truly TF2 compliant.