为什么我在Tensorflow中使用相同文件夹内的图像时,有些图像会被忽略?

我有两个文件夹的数据(训练集有10000张图像,验证集有1000张图像),每个文件夹内有10个子文件夹(分别代表不同的类别)。我将所有这些数据放入了一个数据框架中,以便后续使用。然而,当我使用Tensorflow中的”flow_from_dataframe”函数时,某些文件夹内的图像被认为具有无效的名称,因此被忽略了。

当我尝试在Tensorflow之外访问任何图像时,例如通过简单地打开图像,我仍然无法访问某些文件,尽管路径完全正确。

from PIL import Imageim = Image.open("D:\Ensino Superior\ISCTE-IUL\Mestrado em Engenharia Informatica\Tese\Testagem\TomatoLeafDisease\data\Train\Tomato___Tomato_mosaic_virus\Tomato___Tomato_mosaic_virus_original_f16eeb0f-5219-4a81-9941-351b3d9ba5fc___PSU_CG 2089.JPG_a88e521f-cec2-4755-871f-782de8192056.JPG") im.show() 

尝试访问Tensorflow代码之外的图像时的输出

数据框架

我已经研究过,发现使用绝对路径可能有帮助并使其工作,但即使如此,仍有一些图像被忽略。我该怎么做才能确保没有图像被忽略?

输出错误前的代码:

def create_gen():    train_generator = tf.keras.preprocessing.image.ImageDataGenerator(        preprocessing_function=tf.keras.applications.mobilenet_v2.preprocess_input,        validation_split=0.2    )    test_generator = tf.keras.preprocessing.image.ImageDataGenerator(        preprocessing_function=tf.keras.applications.mobilenet_v2.preprocess_input    )    train_images = train_generator.flow_from_dataframe(        dataframe=train_df,        x_col='Filepath',        y_col='Class',        target_size=(224, 224),        color_mode='rgb',        class_mode='categorical',        batch_size=32,        shuffle=True,        seed=0,        subset='training',        rotation_range=30, # 取消注释以使用数据增强        zoom_range=0.15,        width_shift_range=0.2,        height_shift_range=0.2,        shear_range=0.15,        horizontal_flip=True,        fill_mode="nearest"    )    val_images = train_generator.flow_from_dataframe(        dataframe=train_df,        x_col='Filepath',        y_col='Class',        target_size=(224, 224),        color_mode='rgb',        class_mode='categorical',        batch_size=32,        shuffle=True,        seed=0,        subset='validation',        rotation_range=30, # 取消注释以使用数据增强        zoom_range=0.15,        width_shift_range=0.2,        height_shift_range=0.2,        shear_range=0.15,        horizontal_flip=True,        fill_mode="nearest"    )    test_images = test_generator.flow_from_dataframe(        dataframe=validation_df,        x_col='Filepath',        y_col='Class',        target_size=(224, 224),        color_mode='rgb',        class_mode='categorical',        batch_size=32,        shuffle=False    )    return train_generator,test_generator,train_imagespretrained_model = tf.keras.applications.MobileNetV2(input_shape=(224, 224, 3),include_top=False,weights='imagenet',pooling='avg'train_generator,test_generator,train_images,val_images,test_images = create_gen()

在Tensorflow中使用”flow_from_data_frame”后的输出


回答:

问题解决了。原因是图像的路径和图像名称本身太长了。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注