Python RuntimeError:试图在不构建函数的情况下捕获张量

Python RuntimeError:试图在不构建函数的情况下捕获张量,python,tensorflow,runtime-error,Python,Tensorflow,Runtime Error,我使用tf.data.datsetAPI并使用剩余网络。当我运行TensorBoard代码来可视化嵌入时,我有这个错误,但是当我使用两层网络时,我没有这个问题 def load_and_preprocess_from_path_label(path, label): return load_and_preprocess_image(path), label ds = tf.data.Dataset.from_tensor_slices((all_image_paths, all_ima

我使用
tf.data.datset
API并使用剩余网络。当我运行TensorBoard代码来可视化嵌入时,我有这个错误,但是当我使用两层网络时,我没有这个问题

def load_and_preprocess_from_path_label(path, label):
    return load_and_preprocess_image(path), label

ds = tf.data.Dataset.from_tensor_slices((all_image_paths, all_image_labels))
with tf.Session() as sess:
    # TODO (@omoindrot): remove the hard-coded 10000
    # Obtain the test labels
    image_label_ds = ds.map(load_and_preprocess_from_path_label)
    ds = image_label_ds.shuffle(image_count)

运行时错误回溯(最近一次调用)
在()
92#TODO(@omoindrot):删除硬编码10000
93#获取测试标签
--->94图像\u标签\u ds=ds.map(从\u路径\u标签加载\u和\u预处理\u)
95 ds=图像标签洗牌(图像计数)
96
RuntimeError:试图在不构建函数的情况下捕获张量。

运行以下代码对我很有用:

from keras.models import Sequential
from keras.layers import LSTM, Dense, Dropout
from keras.callbacks import EarlyStopping
from keras import backend as K
import tensorflow as tf


tf.compat.v1.enable_eager_execution()
import tensorflow.compat.v1 as tf
如果您还使用以下代码,在创建模型后强制LSTM清除模型参数和图形,那将非常好

K.clear_session()
tf.compat.v1.reset_default_graph()
#tf.compat.v1.disable_eager_execution()

该错误可能是由于Tensorflow版本造成的


运行以下代码对我很有用:

from keras.models import Sequential
from keras.layers import LSTM, Dense, Dropout
from keras.callbacks import EarlyStopping
from keras import backend as K
import tensorflow as tf


tf.compat.v1.enable_eager_execution()
import tensorflow.compat.v1 as tf
正确的功能:
我在尝试通过调用
tensorflow.python.framework.ops.disable_eager_mode
禁用TF2.0的急切模式时遇到了相同的错误。如果我不点击这个函数,并且在顶层保持渴望,那么错误就消失了。请注意,Keras似乎有一个不同的急切性概念(
dynamic
Model的参数),默认情况下禁用了这个概念。您找到解决方法了吗?