2

Let say I wanted to train an image database with Keras, and I want to automatically generate new images using Keras ImageDataGenerator, the thing is that some functions are not available with the classical settings (flip, shift etc..)

Is it possible to add not only one but a list of functions as "preprocessing function" ?

datagen = dict(
    horizontal_flip=True, 
    vertical_flip=True,
    width_shift_range = 0.1,
    height_shift_range = 0.1,
    data_format = "channels_first",
    preprocessing_function = [foo1, foo2, ...]
)

I also tried to apply my functions before calling the datagen, but I had so many functions that I had MemoryErrors

nuric
  • 11,027
  • 3
  • 27
  • 42
Fou
  • 161
  • 1
  • 9

1 Answers1

0

Updating answer based on comments:

image_gen = ... # without any preprocessing
def mygen():
  for x in image_gen:
    yield x, foo1(x), foo2(x), ...

Maybe there are faster one liners to achieve this but it is clean enough to get things working.

nuric
  • 11,027
  • 3
  • 27
  • 42
  • Thanks for the answer but I don't wont them to be chained, let's say that X is my original input, I want to feed the network with X, foo1(x) and foo2(x) – Fou Sep 22 '18 at 16:15
  • Well yes, that would not work with the above code. You would need to create different generators for each since they actually generate differently. – nuric Sep 22 '18 at 17:17
  • The problem with this is that I don't think I can use multiple generators to feed the network with at the same time? – Fou Sep 22 '18 at 17:38
  • I updated the answer with a wrapper generator that would yield all the pre-processing functions from the image generator as multiple inputs to the network. – nuric Sep 22 '18 at 18:27