0

I want to train my model in Keras, so tried to load images as numpy array and resizing them, but it failed because I don't have enough memory.

MemoryError when I normalize images by img/255

My task is semantic segmentation. I have two folders. One is for the input images and the other is for desired output images. The corresponding images have the same name.

Are there useful API in Keras?

2 Answers2

0

Yes, you should use a generator and the fit_generator function to train with it. Basically in a generator function you have a lot of freedom on how to load the data and in which quantities, so you can load data while the model is training, and only keep one batch of data in memory at a time (plus a queue used by Keras).

Dr. Snoopy
  • 55,122
  • 7
  • 121
  • 140
0

For the preprocessing part: Is it an option to load the images in small batches, do preprocessing and save them again in a one file per batch fashion? Normally after preprocessing the images should be smaller and maybe even small enough to load completely into memory for training.

Also, you can use the train_on_batch or fit_generator function from the model API. Then you can train the images without having them all in-memory at the same time.

dennis-w
  • 2,166
  • 1
  • 13
  • 23