How to do mixup training from image files in Keras

Let’s implement an image data generator that reads images from files and works with Keras model.

fit_generator() out of the box.

The core of the mixup generator consists of a pair of iterators sampling images randomly from directory one batch at a time with the mixup performed in the __next__ method.

Then you can create the training and validation generator for fitting the model, notice that we don’t use mixup in the validation generator.

We can visualize a batch of mixup images and labels with the following snippet in a Jupyter notebook.

The following picture illustrates how mixup works.

Conclusion and further thoughtsYou might be thinking mixing up more than 2 examples at a time might leads to better training, on the contrary, combinations of three or more examples with weights sampled from the multivariate generalization of the beta distribution does not provide further gain, but increases the computation cost of mixup.

Moreover, interpolating only between inputs with equal label did not lead to the performance gains of mixup.

Check out the full source code on my Github.

Tony607/keras_mixup_generatorHow to do mixup training from image files in Keras – Tony607/keras_mixup_generatorgithub.

comShare on Twitter Share on FacebookOriginally published at www.

dlology.

com.

This story is published in The Startup, Medium’s largest entrepreneurship publication followed by +409,714 people.

Subscribe to receive our top stories here.

.

. More details

Leave a Reply