module'tensorflow_core._api.v2.data'没有属性'Iterator'

问题描述 投票:1回答:1

无法弄清楚使用什么代替迭代器

我改用了tf.compat.v1.data.Iterator,但又遇到了另一个错误-AttributeError: 'PrefetchDataset' object has no attribute 'output_types'

代码:

train_ds = prepare_for_train(labeled_ds)

val_ds = tf.data.Dataset.from_tensor_slices(test_data)

#create a iterator with shape and type

iter = tf.data.Iterator.from_structure(train_ds.output_types, train_ds.output_shapes)

"""iter= tf.compat.v1.data.Iterator.from_structure(train_ds.output_types, train_ds.output_shapes)"""
print(iter)


*AttributeError: module 'tensorflow_core._api.v2.data' has no attribute 'Iterator'*

我的T​​F版本2.2.0-dev20200212

谢谢!

tensorflow2.0 tensorflow-datasets
1个回答
0
投票

我能够重现您的错误。这是在Tensorflow Version 2.x中修复它的方法。

© www.soinside.com 2019 - 2024. All rights reserved.