简体   繁体   English

Keras ImageDataGenerator 逻辑是什么?

[英]What is Keras ImageDataGenerator logic?

I was wondering about how the datagenerator works, especially the image multiplying part during training.我想知道数据生成器是如何工作的,尤其是训练期间的图像乘法部分。

I used the generator with .next() and saw the results.我将生成器与.next()一起使用并查看了结果。 But I am a little bit confused if it multiplies images during training.但是如果它在训练期间增加图像,我会有点困惑。

In the lines of code below is the implementation of the generator, but the steps_per_epoch is just the number of the batches of my images len(train_generator.classes) // batch_size .在下面的代码行中是生成器的实现,但是steps_per_epoch只是我的图像的批次数len(train_generator.classes) // batch_size So if my database consists of 1024 images, I will get 16 batches with 64 images in each, as well as I will have 16 steps per epoch.因此,如果我的数据库包含 1024 张图像,我将获得 16 个批次,每个批次有 64 张图像,每个 epoch 将有 16 个步骤。 So if I am doing steps just for my initial images, where do the multiplied images go?因此,如果我只是为我的初始图像执行步骤,那么乘法图像 go 在哪里? Or maybe I don't really understand the step_per_epoch part?或者我可能不太了解step_per_epoch部分?

# Import of the data
data_generator = ImageDataGenerator(
        #rescale=1.0/255.0,
        rotation_range=10,
        width_shift_range=0.1,
        horizontal_flip=True,
        height_shift_range=0.1,
        validation_split=0.3
        )

train_generator = data_generator.flow_from_directory(
        train_path,
        target_size=(img_height, img_width),
        batch_size=batch_size,
        color_mode="grayscale",
        class_mode="categorical",
        subset="training"
        )

model.fit(train_generator,
                 steps_per_epoch=len(train_generator.classes) // batch_size,
                 epochs=epoch_n,
                 validation_steps=len(valid_generator.classes) // batch_size,
                 validation_data=valid_generator,
)

This is not exactly how ImageDataGenerator works, it does not "multiply" your data.这不是ImageDataGenerator的工作方式,它不会“增加”您的数据。 If you don't pass any argument during the instantiation, it will just fetch your images from the folder and feed them, unspoiled to the network.如果您在实例化过程中不传递任何参数,它只会从文件夹中获取您的图像并将它们提供给网络,而不会受到破坏。

When you add: rotation_range , width_shift_range ... you are instructing the data_generator to apply random modification to the incoming images within the specified range.当您添加: rotation_rangewidth_shift_range ...时,您指示data_generator对指定范围内的传入图像应用随机修改。 These are random augmentation during the training, they are not pushed after your done with your initial data.这些是训练期间的随机增强,在您完成初始数据后不会推送它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM