keras - 运行 Tensorflow 2.0 代码给出 'ValueError: tf.function-decorated function tried to create variables on non-first call' 。我究竟做错了什么?

标签 keras deep-learning keras-layer tensorflow2.0 tf.keras

error_giving_notebook

non_problematic_notebook

可以看出,我在“error_giving_notebook”中使用了 tf.function 装饰器,它会抛出 ValueError,而同一笔记本除了删除 tf.function 装饰器之外没有任何更改,可以在“non_problematic_notebook”中顺利运行。可能是什么原因?

最佳答案

当您尝试在 TF 2.0 中使用函数装饰器时,请在导入 TensorFlow 后使用以下行立即启用 run 函数:

tf.config.experimental_run_functions_eagerly(True)

由于上述内容已被弃用(不再是实验性的?),请使用以下内容:

tf.config.run_functions_eagerly(True)

如果您想了解更多信息,请参阅 this链接。

关于keras - 运行 Tensorflow 2.0 代码给出 'ValueError: tf.function-decorated function tried to create variables on non-first call' 。我究竟做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58352326/

相关文章:

deep-learning - Keras 和 GPU 使用

python - 通过哪种适应时间序列的技术可以替换 Python 中的 Keras MLP 回归模型中的交叉验证

python - tensorflow 警告 : The graph couldn't be sorted in topological order?

tensorflow - 输出层的 softmax 和 sigmoid 函数

machine-learning - 即使我的 CNN 模型正在进行回归,我是否可以对输出层使用 Sigmoid 激活?

Keras TimeDistributed Conv1D 错误

tensorflow - 可以动态指定 Keras RepeatVector 重复吗?

keras - 如何处理keras中的单输出多损失?

keras - 如何在单个正则化函数中正则化层的内核权重偏差权重?

machine-learning - Keras:内核和事件正则化器之间的区别