首页 文章

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

提问于
浏览
4

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

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

1 回答

  • 2

    你可能会这样做:

    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
    

相关问题