【发布时间】: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