python - Python:系统找不到指定的路径,Tensorflow
问题描述
我是深度学习的新手,我想为斗鱼制作图像分类项目,但是当我使用 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')
那么错误将是这样的:
---------------------------------------------------------------------------
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'
解决方案
除非 tmp 在您所在的当前目录中,否则您需要在 flow_from_directory 中指定完整路径。例如
train_dir=r'c:\whatever\temp\train'
推荐阅读
- graphql - How to send byte array (Blob) to GraphQL mutation
- android - How can I have my Substratum Theme change two parts of the same file as two different options?
- php - How to set file permissions in google cloud app engine
- javascript - 如何从 Array.map() 函数正确返回异步数据
- rust - 将动态库注入线程
- docker - 如何在golang的容器中获取磁盘设备信息?
- verilog - 在 Verilog 中,“for 循环”可以是可变大小的吗?
- jquery - 隐藏按钮后显示按钮的问题
- elasticsearch - ElasticSearch must-terms 不返回数据
- bootstrap-4 - aria-expanded="false" 在引导模板中不起作用