How to give variable size images as input in keras

后端 未结 3 701
我寻月下人不归
我寻月下人不归 2020-12-19 07:44

I am writing a code for image classification for two classes using keras with tensorflow backend. My images are stored in folder in computer and i want to give these images

3条回答
  •  时光说笑
    2020-12-19 08:28

    Unfortunately you can't train a neural network with various size images as it is. You have to resize all images to a given size. Fortunately you don't have to do this in your hard drive, permanently by keras does this for you on hte fly.

    Inside your flow_from_directory you should define a target_size like this:

    train_generator = train_datagen.flow_from_directory(
        'data/train',
        target_size=(150, 150), #every image will be resized to (150,150) before fed to neural network
        batch_size=32,
        class_mode='binary')
    

    Also, if you do so, you can have whatever batch size you want.

提交回复
热议问题