如何在Keras中使用ImageDataGenerator调整标签?

我想用Keras的
ImageDataGenerator增加我的数据集,用于
model.fit_generator().我看到我可以随机翻转图像.对于翻转图像,我需要修改相应的标签.我怎样才能做到这一点?

编辑:我正在做回归,而不是分类,所以如果翻转图像,我需要调整标签.实际图像来自自动驾驶汽车模拟器,标签是转向角.如果我水平翻转图像,我需要否定转向角度.

最佳答案 你可能会这样做:

import numpy

def fliping_gen(image_generator, flip_p=0.5):
    for x, y in image_generator:
         flip_selector = numpy.random.binomial(1, flip_p, size=(x.shape[0]) == 1
         x[flip_selector,:,:,:] = x[flip_selector,:,::-1,:])
         y[flip_selector] = (-1) * y[flip_selector])
         yield x, y
点赞