【问题标题】:AttributeError: 'generator' object has no attribute 'next'AttributeError:“生成器”对象没有属性“下一个”
【发布时间】:2018-02-18 03:13:19
【问题描述】:

使用python 3.6,我从tflearn.data_utils导入image_preloader

然后写

X, Y = image_preloader("\\all\\train", image_shape=(128, 128), mode='folder', categorical_labels=True, normalize=True)

train 文件夹中有带有标签的文件夹。在这些标记的文件夹中是图像。

我得到这个错误:

    C:\Users\Daman\.conda\envs\TF\python.exe 
    "C:/Users/Daman/PycharmProjects/Coin Classification/main.py"
    hdf5 is not supported on this machine (please install/reinstall h5py for                         
    optimal experience)
    curses is not supported on this machine (please install/reinstall curses                 
    for an optimal experience)
    Scipy not supported!
    Traceback (most recent call last):
      File "C:\Users\Daman\.conda\envs\TF\lib\site-
    packages\tflearn\data_utils.py", line 730, in directory_to_samples
        classes = sorted(os.walk(directory).next()[1])
    AttributeError: 'generator' object has no attribute 'next'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:/Users/Daman/PycharmProjects/Coin Classification/main.py", line 
    3, in <module>
        X, Y = image_preloader("\\all\\train", image_shape=(640,480), 
    mode='folder', categorical_labels=True, normalize=True)
      File "C:\Users\Daman\.conda\envs\TF\lib\site-
    packages\tflearn\data_utils.py", line 512, in image_preloader
        flags=files_extension, filter_channel=filter_channel)
      File "C:\Users\Daman\.conda\envs\TF\lib\site-
    packages\tflearn\data_utils.py", line 732, in directory_to_samples
         classes = sorted(os.walk(directory).__next__()[1])
    StopIteration

我该如何解决这个错误?

【问题讨论】:

  • 我看到了那个帖子。我是否打算更改实际 python 代码的第 730 行?我试过了,还是不行。
  • 更新您的tflearn 安装。 code on github 没有这个错误(或者更确切地说,捕获了这个错误)。你是如何/从哪里安装tflearn的?
  • 那你的问题不一样了,你正在尝试使用不支持 python3 的 3rd 方模块,可能会找到支持 python3 的正确版本
  • 是的,这看起来像您正在尝试使用 Python 3 解释器运行 Python 2 版本的库

标签: python tensorflow tflearn


【解决方案1】:

我也在处理同样的问题,python 2 支持 g.next(),现在你可以使用 next(g) python 3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多