I want to augment my dataset with Keras's ImageDataGenerator for use with model.fit_generator(). I see I can randomly flip images. For flipped images, I need to modify the corresponding label. How can I do that?
EDIT: I'm doing regression, not classification, so if an image is flipped I need to adjust the label. The actual images are from a self-driving car simulator, and the labels are the steering angles. If I horizontally flip an image, I need to negate the steering angle.
You might do something like:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With