I have implemented a customized generator with keras.utils.Sequence, using the method proposed from this post: A detailed example of how to use data generators with Keras.