我正在使用pandas来使用.txt文件和flow_from_dataframe来帮助我读取文件夹中的图像。
这是我的代码:
import keras
import pandas as pd
from keras_preprocessing import image
from keras.preprocessing.image import ImageDataGenerator
datagen = image.ImageDataGenerator(rescale=1./255)
data = pd.read_csv('/directory/clipart_train.txt', sep=" ", header=None)
data.columns = ["id", "labels"]
print(data)
print(data["id"].shape)
print(data["labels"].shape)
data["labels"] = data["labels"].astype('str')
print(data["labels"].dtype)
train_generator=datagen.flow_from_dataframe(
dataframe = data,
directory = "/directory/",
x_col = "id",
y_col = "labels",
target_size=(224,224),
class_mode = 'categorical',
batch_size = 1
)
我得到以下格式:[11372行x 2列],打印命令显示“标签”,范围从0到204。
但Flow_from_dataframe产生'找到属于181个类的11372个图像'。而不是205班。我错过了什么吗?
编辑:使用类似代码的验证数据不会出现问题(找到属于204类的1954图像)。