How to fix “ResourceExhaustedError: OOM when allocating tensor”

前端 未结 3 1812
独厮守ぢ
独厮守ぢ 2021-01-03 01:31

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

# define two sets of inputs
inputA = Input(shape=(32,64,1))
inputB = Input(sh         


        
相关标签:
3条回答
  • 2021-01-03 01:55

    From [800000,32,30,62] it seems your model put all the data in one batch.

    Try specified batch size like

    history = model.fit([trainimage, train_product_embd],train_label, validation_data=([validimage,valid_product_embd],valid_label), epochs=10, steps_per_epoch=100, validation_steps=10, batch_size=32)
    

    If it still OOM then try reduce the batch_size

    0 讨论(0)
  • 2021-01-03 02:20

    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 neurons in your Dense, Conv2D layers
    • Use a smaller batch_size (or increase steps_per_epoch and validation_steps)
    • Use grayscale images (there will be one channel instead of three)
    • Reduce the number of layers
    • Use more MaxPooling2D layers, and increase their pool size
    • Use larger strides in your Conv2D layers
    • Reduce the size of your images (you can use PIL or cv2 for that)
    • Apply dropout
    • Use smaller float precision, namely np.float32 if you accidentally used np.float64
    • If you're using a pre-trained model, freeze the first layers

    There is more useful information about this error:

    OOM when allocating tensor with shape[800000,32,30,62]
    

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

    0 讨论(0)
  • 2021-01-03 02:20

    Happened to me as well.

    You can try reducing trainable parameters by using some form of Transfer Learning - try freezing the initial few layers and use lower batch sizes.

    0 讨论(0)
提交回复
热议问题