【问题标题】:RuntimeError: as_numpy_iterator() is not supported while tracing functionsRuntimeError:跟踪函数时不支持 as_numpy_iterator()
【发布时间】:2020-02-03 19:32:34
【问题描述】:

当我使用函数 as_numpy_iterator() 时出错

----------------------------------- ---------------------------- RuntimeError Traceback(最近一次调用 最后)在() ----> 1 张图片 = get_image_data(image_paths)

1 帧 /tensorflow-2.1.0/python3.6/tensorflow_core/python/data/ops/dataset_ops.py 在 as_numpy_iterator(self) 第488章 489 如果不是 context.executing_eagerly(): --> 490 raise RuntimeError("as_numpy_iterator() is not supported while tracking " 第491章 492 for component_spec in nest.flatten(self.element_spec):

RuntimeError: 跟踪时不支持 as_numpy_iterator() 功能

我的代码是

    # creating a function called get_dataset, which creates a dataset of image data from file paths.
def get_dataset(image_paths):
  filename_tensor = tf.constant(image_paths)
  dataset = tf.data.Dataset.from_tensor_slices(filename_tensor)
  def _map_fn(filename):
    return decode_image(filename=filename)
  return dataset.map(_map_fn)
#
def get_image_data(image_paths):
  dataset = get_dataset(image_paths)
  return list(dataset.as_numpy_iterator())
image = get_image_data(image_paths)

在使用 dataset.as_numpy_iterator() 时会引发错误。我使用了两个文件名数组的图像路径

【问题讨论】:

  • 您能否提供可重现的代码来帮助我们解决您的问题?
  • 对不起,我使用的是 1.0 tensorflow。我现在搬到了pytorch。但我确实喜欢 tf。
  • 请像 pytorch 一样制作论坛。

标签: python numpy tensorflow


【解决方案1】:

这里的错误消息有点令人困惑,因为它谈到了跟踪功能,但我遇到了这个并意识到它是一个数据集功能,只有在启用急切执行时才支持。它在 TensorFlow 2.x 中默认启用,但您也可以在以后的 1.x 版本中手动启用它。如果启用它,此错误消息应该会消失。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    相关资源
    最近更新 更多