RuntimeError:尝试在不构建函数的情况下捕获 EagerTensor [英] RuntimeError: Attempting to capture an EagerTensor without building a function

查看:117
本文介绍了RuntimeError:尝试在不构建函数的情况下捕获 EagerTensor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 tf.data.datset API 并使用残差网络.当我为 TensorBoard 运行代码以可视化我的嵌入时,我遇到了这个错误,但是当我使用两层网络时,我没有这个问题.

I use tf.data.datset API and use residual network. When I run code for TensorBoard for visualizing my embeddings I have this error, but when I use a two layers network I don't have this problem.

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)

<小时>

RuntimeError                              Traceback (most recent call last)
<ipython-input-41-ead5d6a54baa> in <module>()
     92         # TODO (@omoindrot): remove the hard-coded 10000
     93         # Obtain the test labels
---> 94         image_label_ds = ds.map(load_and_preprocess_from_path_label)
     95         ds = image_label_ds.shuffle(image_count)
     96 
RuntimeError: Attempting to capture an EagerTensor without building a function.

推荐答案

错误可能是Tensorflow版本问题

The error is possibly due to Tensorflow version

运行以下代码对我有用:

Running the following code worked for me:

import tensorflow.compat.v1 as tf

正确的功能:

tf.disable_v2_behavior()

这篇关于RuntimeError:尝试在不构建函数的情况下捕获 EagerTensor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆