0

I am using the Keras ImageDataGenerator to process the inputs to my CNN. I want to basic preprocessing that scales the image pixels to values from -1 to 1 as it was done in the paper of the Mobilenet architecture.

My datagenerator only defines the preprocessing function:

train_datagen = ImageDataGenerator(
    preprocessing_function=preprocess_input
)

My preprocess_input function:

def preprocess_input(img):
    pix = np.asarray(img)
    pix = pix.astype(np.float32)
    pix = pix / 255.0
    pix = pix * 2
return pix

This is giving me the follwing error:

Traceback (most recent call last):   File "finetune_mobilenet.py",
line 206, in <module>
    train(folder_train, folder_dev, './models/')   File "finetune_mobilenet.py", line 150, in train
    callbacks=callbacks_list)   File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py",
line 91, in wrapper
    return func(*args, **kwargs)   File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py",
line 2192, in fit_generator
    generator_output = next(output_generator)   File "/usr/local/lib/python2.7/dist-packages/keras/utils/data_utils.py",
line 584, in get
    six.raise_from(StopIteration(e), e)   File "/usr/local/lib/python2.7/dist-packages/six.py", line 737, in
raise_from
    raise value StopIteration: 'tuple' object cannot be interpreted as an index

I also tried the original preprocessing function that is available for the Mobilenet architecture in Keras but that one also fails. Can you tell what I need to change to zero-center my image data?

Ankur Ankan
  • 2,953
  • 2
  • 23
  • 38
Gegenwind
  • 1,388
  • 1
  • 17
  • 27
  • We probably cannot tell the error from the posted code alone, and need to see the whole Python source file. But I can say that since the error is raised from the `six` module, it likely means it is an error with Python 2 vs. Python 3 syntax. Maybe you are trying to iterate a dictionary or something and you're using the wrong `six` function, or the iteration is giving you a `tuple` but you're treating it like it is an integer index somewhere, etc. – ely Mar 19 '18 at 13:23
  • @ely thank you for your advice. Your first guess was correct, upgraded to Python3 the problem disappears. I did not even think about a compatibility issue. I probably need to pay closer attention to errors originating from pythons distribution files. – Gegenwind Mar 19 '18 at 15:30

0 Answers0