使用Keras进行数据增强可以产生几乎白色的图像

时间:2019-04-08 08:15:48

标签: python keras data-augmentation

我正在尝试使用keras ImageDataGenerator进行数据增强。 我从一个数据框中提取图像,该数据框中的一列包含图像的路径,另一列包含标签。现在,我只想水平翻转图像。但是当我绘制图像时,图像看起来就像亮度被调到最大。我不知道这是怎么回事...有什么想法吗?

datagen = ImageDataGenerator(horizontal_flip=True)


# Configure batch size and retrieve one batch of images
for X_batch, y_batch in datagen.flow_from_dataframe(dataframe=data,
    x_col="File name",
    y_col="Driving direction",
    directory = "Self-Driving-Car/Training Data/",
    target_size = (480, 640),
    class_mode = "other"):
    # Show 9 images
    for i in range(0, 9):
        plt.subplot(330 + 1 + i)
        plt.imshow(X_batch[i])
    plt.show()
    break

Here is one original image

Here are the augmented images

2 个答案:

答案 0 :(得分:1)

更一般地说,请注意,如果您没有 0-255 范围内的 int 图像,ImageDataGenerator 可以根据某些增强选项的某些默认值将数据重新缩放到 0-255,而不是其他选项。亮度范围是一个重新缩放到 0-255 的示例。

答案 1 :(得分:0)

好吧,这只是一个绘图问题,这解决了它:

    plt.imshow(X_batch[i]/255)