__iter__() is only supported inside of tf.function or when eager execution is enabled
程序员文章站
2024-01-19 09:17:58
...
运行tensorflow代码出现这个
__iter__() is only supported inside of tf.function or when eager execution is enabled
按照字面意思就是需要增加eager execution,于是这样进行修改:
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
但会出现错误:
AttributeError: module 'tensorflow.contrib.eager' has no attribute 'enable_eager_execution'
在github里面看到有人遇到过这个问题,实际是版本的锅,这样就ok
import tensorflow as tf
tf.enable_eager_execution()
注:我使用的是tensorflow1.15