[英]Python: The system cannot find the path specified , 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'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.