简体   繁体   English

Python:系统找不到指定的路径,Tensorflow

[英]Python: The system cannot find the path specified , Tensorflow

i'm new in deep learning, and i want make image classification project for betta fish, but i got a problem with my code while i'm use gerator to read my image, someone could help me?我是深度学习的新手,我想为斗鱼制作图像分类项目,但是我在使用 gerator 读取图像时遇到了代码问题,有人可以帮助我吗?

from tensorflow.keras.preprocessing.image import ImageDataGenerator
# All images will be rescaled by 1./255
train_datagen = ImageDataGenerator(rescale=1./255)
# Flow training images in batches of 128 using train_datagen generator
train_generator = train_datagen.flow_from_directory(
        '\\tmp\Train',  # This is the source directory for training images
        target_size=(300, 300),  # All images will be resized to 150x150
        batch_size=128,
        # Since we use binary_crossentropy loss, we need binary labels
        class_mode='binary')

then the error would be like this:那么错误将是这样的:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-24-fec6e611274c> in <module>
     10         batch_size=128,
     11         # Since we use binary_crossentropy loss, we need binary labels
---> 12         class_mode='binary')

~\anaconda3\lib\site-packages\keras_preprocessing\image\image_data_generator.py in flow_from_directory(self, directory, target_size, color_mode, classes, class_mode, batch_size, shuffle, seed, save_to_dir, save_prefix, save_format, follow_links, subset, interpolation)
    538             follow_links=follow_links,
    539             subset=subset,
--> 540             interpolation=interpolation
    541         )
    542 

~\anaconda3\lib\site-packages\keras_preprocessing\image\directory_iterator.py in __init__(self, directory, image_data_generator, target_size, color_mode, classes, class_mode, batch_size, shuffle, seed, data_format, save_to_dir, save_prefix, save_format, follow_links, subset, interpolation, dtype)
    104         if not classes:
    105             classes = []
--> 106             for subdir in sorted(os.listdir(directory)):
    107                 if os.path.isdir(os.path.join(directory, subdir)):
    108                     classes.append(subdir)

FileNotFoundError: [WinError 3] The system cannot find the path specified: '\\tmp\\Train'

unless tmp is in the current directory you are in you need to specify the full path in flow_from_directory.除非 tmp 在您所在的当前目录中,否则您需要在 flow_from_directory 中指定完整路径。 for example例如

train_dir=r'c:\whatever\temp\train'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM