python - RuntimeError : tf. placeholder() 与急切执行不兼容

标签 python python-3.x tensorflow tensorflow2.0

我已使用 tf_upgrade_v2 TF1 代码升级到 TF2。我对两者都是菜鸟。我得到了下一个错误:

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

我有一些 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))

你能给我一些关于如何进行的建议吗?任何“快速”解决方案?还是我应该重新编码?

最佳答案

我在这里找到了一个简单的解决方案:disable Tensorflow eager execution

基本上是:
tf.compat.v1.disable_eager_execution()
有了这个,您可以禁用默认的激活急切执行,并且您不需要更多地接触代码。

关于python - RuntimeError : tf. placeholder() 与急切执行不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56561734/

相关文章:

python - Tensorflow - 无法在 Estimator 中使用带有 MirroredStrategy 分布的 BasicLSTMCell

python - 如果 Django 中已经存在某些表,如何强制迁移到数据库?

python - 为什么 tf.Variable 可迭代但不能迭代

tensorflow - 安装 tensorflow 时包 'ffmpeg' 没有安装候选

python - python中双向哈希的最佳实践?

python - 了解字典的用例

python - 将新值添加到 txt 文件

python-3.x - 将文本文件的每一行写入单独的文本文件并使用不同的名称保存

python - 如何将字典的格式更改为 value1;key1;在 Python 3.6 中?

python - TensorFlow 估计器混淆矩阵