从keras数据生成器产生数据

时间:2018-07-27 01:42:10

标签: keras

我希望预览keras图像数据生成器的输出。我如何从一个生成器中生成5张图像?

train_datagen = ImageDataGenerator(
        rescale=1./255,
        shear_range=0.2,
        zoom_range=0.2,
        horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
        'data/train',
        target_size=(150, 150),
        batch_size=32,
        class_mode='binary')

尝试通过迭代器的常规方法似乎无效

for image in train_generator:
    print(image)

AttributeError: 'DirectoryIterator' object has no attribute 'next'

1 个答案:

答案 0 :(得分:0)

这会从数据集中产生前三张图像:

public static boolean removeEmployee(Employee employee)
{
    employee.setEmployees(employee.getEmployees().stream().filter(Employee::removeEmployee).collect(Collectors.toList()));
    return !(employee.getSalary()==0 && employee.getEmployees().size()==0);
}