xxxxxxxxxx
What fixed it for me:
Use either tf.config.run_functions_eagerly(True), or compile the model with the flag run_eagerly=True.
Then, add if tf.executing_eagerly(): before calling the .numpy() function.
TF version: 2.5.0, I use tensorflow.keras.
xxxxxxxxxx
Eager execution is enabled by default in version 2.x
You can check that by using:
tf.executing_eagerly()