我尝试使用Keras中的ImageDataGenerator将validation_split设置为某个分数来拆分数据(图像)。
这是我代码
#Generate batches of tensor image data with real-time data augmentation,
looped over in batches
train_DataGen_Augmnt =ImageDataGenerator(
rescale=1./255,
featurewise_center=True,
validation_split=0.2,
rotation_range=30,
horizontal_flip=True,
)
#validation data not augmented!
Validation_DataGen = ImageDataGenerator(rescale=1./255)
# Flow training images in batches of 32 using train_datagen generator
train_generator = train_DataGen_Augmnt.flow_from_directory(
base_dir,
subset='training',
target_size=(150, 150),
batch_size=32,
#save_to_dir='images/Agumented'
)
# Flow validation images in batches of 32 using test_datagen generator
validation_generator = Validation_DataGen.flow_from_directory(
base_dir,
subset='validation',
target_size=(150, 150),
batch_size=32,
)
分割似乎在分割数据时起作用,但仅显示用于训练的分割
以下是运行此命令时的输出
Found 89 images belonging to 3 classes.
Found 0 images belonging to 3 classes.
2条答案
按热度按时间zvms9eto1#
使用与训练数据生成
train_DataGen_Augmnt
相同的发生器生成确认数据2ul0zpep2#
不要忘记在validation_data_gen中也输入validation_split = 0.2,这样就可以正常工作