RuntimeError: tf.placeholder() is not compatible with eager execution

AMGMNPLK picture AMGMNPLK · Jun 12, 2019 · Viewed 49.5k times · Source

I have upgraded with tf_upgrade_v2 TF1 code to TF2. I'm a noob with both. I got the next error:

RuntimeError: tf.placeholder() is not compatible with eager execution.

I have some tf.compat.v1.placeholder().

self.temperature = tf.compat.v1.placeholder_with_default(1., shape=())
self.edges_labels = tf.compat.v1.placeholder(dtype=tf.int64, shape=(None, vertexes, vertexes))
self.nodes_labels = tf.compat.v1.placeholder(dtype=tf.int64, shape=(None, vertexes))
self.embeddings = tf.compat.v1.placeholder(dtype=tf.float32, shape=(None, embedding_dim))

Could you give me any advice about how to proceed? Any "fast" solutions? or should I to recode this?

Answer

AMGMNPLK picture AMGMNPLK · Jun 12, 2019

I found an easy solution here: disable Tensorflow eager execution

Basicaly it is:

tf.compat.v1.disable_eager_execution()

With this, you disable the default activate eager execution and you don't need to touch the code much more.