您可以使用图像数据生成器。您需要解压缩文件并将列标题添加到 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 对象作为训练输入
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句