Skip to content
Advertisement

How to fix “ResourceExhaustedError: OOM when allocating tensor”

I wanna make a model with multiple inputs. So, I try to build a model like this.

JavaScript

and the summary : _

But, when i try to train this model,

JavaScript

the problem happens…. :

JavaScript

Thanks for reading and hopefully helping me :)

Advertisement

Answer

OOM stands for “out of memory”. Your GPU is running out of memory, so it can’t allocate memory for this tensor. There are a few things you can do:

  • Decrease the number of filters in your Dense, Conv2D layers
  • Use a smaller batch_size (or increase steps_per_epoch and validation_steps)
  • Use grayscale images (you can use tf.image.rgb_to_grayscale)
  • Reduce the number of layers
  • Use MaxPooling2D layers after convolutional layers
  • Reduce the size of your images (you can use tf.image.resize for that)
  • Use smaller float precision for your input, namely np.float32
  • If you’re using a pre-trained model, freeze the first layers (like this)

There is more useful information about this error:

JavaScript

This is a weird shape. If you’re working with images, you should normally have 3 or 1 channel. On top of that, it seems like you are passing your entire dataset at once; you should instead pass it in batches.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement