Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image Tensorflow&x2019;来自\u目录的s流\u返回错误集_Image_Tensorflow2.0_Multiclass Classification - Fatal编程技术网

Image Tensorflow&x2019;来自\u目录的s流\u返回错误集

Image Tensorflow&x2019;来自\u目录的s流\u返回错误集,image,tensorflow2.0,multiclass-classification,Image,Tensorflow2.0,Multiclass Classification,我使用ImageDataGenerator从标记的图像目录中创建验证集(用于使用TF(Keras)的图像分类。目录为0,1,2,3,4,对应于每个图像的类,它们分别包含488、185、130、131、91个图像 train_image_generator = ImageDataGenerator(rescale=1./255) # Generator for our training data # validation_image_generator = ImageDataGenerator(r

我使用ImageDataGenerator从标记的图像目录中创建验证集(用于使用TF(Keras)的图像分类。目录为0,1,2,3,4,对应于每个图像的类,它们分别包含488、185、130、131、91个图像

train_image_generator = ImageDataGenerator(rescale=1./255) # Generator for our training data
# validation_image_generator = ImageDataGenerator(rescale=1./255) # Generator for our validation data
train_data_gen = train_image_generator.flow_from_directory(batch_size=batch_size,
                                                           directory=train_dir,
                                                           shuffle=True,
                                                           target_size=(IMG_HEIGHT, IMG_WIDTH),
                                                           class_mode='categorical')
返回

Found 0 images belonging to 5 classes.
下面的代码是什么

validation_data_generator = train_image_generator.flow_from_directory(
    train_dir, # same directory as training data
    target_size=(IMG_HEIGHT, IMG_WIDTH),
    batch_size=batch_size,
    class_mode='categorical',
    subset='validation') # set as validation data
产出:

Found 0 images belonging to 5 classes.
请问怎么了?我想验证集上一节课至少有几张图片

任何帮助都将不胜感激


CS

很难说不看目录字符串是什么,但我怀疑问题可能是“train\u dir”变量中的字符。您可以尝试使用os.path.exists(train\u dir)查看代码是否实际指向正确的位置,或者使用os.listdir查看文件是否以这种方式显示

在创建数据生成器之前,将这一行放到其中可能会解决此问题:

import os
train_dir=os.path.normpath(train_dir)

通常我发现问题在于路径中的斜杠。如果您只想使用字符串,通常需要使用双反斜杠(\)或单正斜杠(/),而不是通常在路径中看到的单反斜杠。当文件名或子目录以数字开头时(就像您的文件名或子目录一样),这一问题尤其严重.

很难说不看目录字符串是什么,但我怀疑问题可能是“train\u dir”变量中的字符。您可以尝试使用os.path.exists(train\u dir)查看代码是否实际指向正确的位置,或者使用os.listdir查看文件是否以这种方式显示

在创建数据生成器之前,将这一行放到其中可能会解决此问题:

import os
train_dir=os.path.normpath(train_dir)

通常我发现问题在于路径中的斜杠。如果您只想使用字符串,通常需要使用双反斜杠(\)或单正斜杠(/),而不是通常在路径中看到的单反斜杠。当文件名或子目录以数字开头时(就像您的文件名或子目录一样),这一问题尤其严重.

嗨,os.path.exists(train\u dir)完成了这项工作。谢谢。别担心。这让我第一次遇到它时也发疯。嗨,os.path.exists(train\u dir)完成了这项工作。谢谢。别担心。这让我第一次遇到它时也发疯了。