How to give variable size images as input in keras

后端 未结 3 717
我寻月下人不归
我寻月下人不归 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:36

    You can train variable sizes, as long as you don't try to put variable sizes in a numpy array.

    But some layers do not support variable sizes, and Flatten is one of them. It's impossible to train models containing Flatten layers with variable sizes.

    You can try, though, to replace the Flatten layer with either a GlobalMaxPooling2D or a GlobalAveragePooling2D layer. But these layers may condense too much information into a small data, so it might be necessary to add more convolutions with more channels before them.

    You must make sure that your generator will produce batches containing images of the same size, though. The generator will fail when trying to put two or more images with different sizes in the same numpy array.

提交回复
热议问题