Python 将数据加载到X_列和Y_列
如果这是我的数据组织,我将如何将这些数据加载到x_train和y_train中以制作keras模型 train.zip 用于训练集的图像文件 train.txt 训练集的标签 test.zip 测试集的图像文件 这就是train.txt的样子 以下是zip文件的外观: 我不知道该如何加载这些数据,这样我就可以为x_-train、y_-train和x_-test和y_-test制作一个CNN模型。我试过很多东西,但运气不好你可以用一个。 您需要解压缩文件,并在txt文件中添加列标题。 例如:Python 将数据加载到X_列和Y_列,python,tensorflow,machine-learning,artificial-intelligence,Python,Tensorflow,Machine Learning,Artificial Intelligence,如果这是我的数据组织,我将如何将这些数据加载到x_train和y_train中以制作keras模型 train.zip 用于训练集的图像文件 train.txt 训练集的标签 test.zip 测试集的图像文件 这就是train.txt的样子 以下是zip文件的外观: 我不知道该如何加载这些数据,这样我就可以为x_-train、y_-train和x_-test和y_-test制作一个CNN模型。我试过很多东西,但运气不好你可以用一个。 您需要解压缩文件,并在txt文件中添加列标题。 例如:
Filename Label
train/0.jpg 5
train/1.jpg 21
现在,您可以使用pandas读取txt文件,然后使用ImageDataGenerator:
df = pandas.read_csv("uos-com2028/train/train.txt", delim_whitespace=True)
columns = [
"Label",
]
# you may want to rescale your image if it goes from 0 to 255
datagen = ImageDataGenerator(
rescale=1./255.,
)
# you will want to change color_mode, batch_size, and target_size depending on your image
traindata = datagen.flow_from_dataframe(
dataframe=df,
directory="uos-com2028/train",
x_col="Filename",
y_col=columns,
color_mode='rgb',
batch_size=16,
class_mode="raw",
target_size=(256, 256),
shuffle=True,
)
然后,您可以在运行model.fit()时使用traindata对象作为您的培训输入。谢谢,我会尝试一下,如果您不介意的话,我可以通过电子邮件与您联系,这样我就可以向您发送一个kaggle链接,这样我们就可以一起尝试了。我很失落没问题。你可以通过电话联系我endermanaresassy@gmail.com