Search code examples
pythontensorflowkerasfeed

How do I Feed local Data (Images) into my Keras Network in Python?


I am using the newest version of Tensorflow and Keras. I have seen the example where datasets like the MNIST ist loaded and used.

But how do I do this with local images?


Solution

  • You can also use ImageDataGenerator, which shuffles your data and can do augmentation for you (see https://keras.io/preprocessing/image/ ).

    from keras.preprocessing.image import ImageDataGenerator
    
    image_datagen = ImageDataGenerator(rescale=1./255)
    
    image_generator = image_datagen.flow_from_directory(
        'your_training_images/train',
        target_size=(image_height, image_width),
        batch_size=batch_size,
        class_mode='binary')