解决Tensor flow 2.0-AttributeError: module ‘tensorflow_core._api.v2.data‘ has no attribute ‘Iterator错误

1. 报错信息如下

报错如下:


AttributeError                            Traceback (most recent call last)
<ipython-input-48-3f129f8c1fc2> in <module>
----> 1 iterator = tf.data.Iterator.from_structure(dataset_image.output_types, dataset_image.output_shapes)
      2 real_image_batch, wrong_image_batch = iterator.get_next()

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

2 . 解决办法

将报错代码

iterator = tf.data.Iterator.from_structure(dataset_image.output_types, dataset_image.output_shapes)

改为如下形式:

iterator = tf.compat.v1.data.Iterator.from_structure(tf.compat.v1.data.get_output_types(dataset_image), 
                                                     tf.compat.v1.data.get_output_shapes(dataset_image))

你可能感兴趣的:(配置深度学习环境,tensorflow,深度学习,人工智能)