Skip to main content
 首页 » 编程设计

python之属性错误 : 'generator' object has no attribute 'next'

2025年01月19日9dyllove98

使用 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 2支持g.next(),现在你可以使用next(g) python 3