keras 图像数据生成器中的validation_split返回0张图像

7gyucuyw  于 2022-12-29  发布在  其他
关注(0)|答案(2)|浏览(137)

我尝试使用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.
zvms9eto

zvms9eto1#

使用与训练数据生成train_DataGen_Augmnt相同的发生器生成确认数据

2ul0zpep

2ul0zpep2#

不要忘记在validation_data_gen中也输入validation_split = 0.2,这样就可以正常工作

相关问题