我在使用函数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(自己)中 488“”“ 第489章真相大白 -> 490提高RuntimeError(“在跟踪“时不支持as_numpy_iterator() 491个“功能”) 492对于nest.flatten(self.element_spec)中的component_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()
会引发错误。我使用了两个文件名数组的图像路径
答案 0 :(得分:1)
这里的错误消息有点令人困惑,因为它谈到了跟踪函数,但是我遇到了这个问题,并且意识到只有启用了急切执行时才支持的数据集功能。 TensorFlow 2.x默认情况下已启用它,但您也可以在更高版本的1.x中手动启用它。如果启用它,此错误消息应该消失。