MATLAB: Do I get the memory error when using trainNetwork function

cnnerrorgpu

When I run trainNetwork function with CNN(deep neural network), I get the following error.
Error using nnet.internal.cnngpu.convolveForward2D
Out of memory on device. To view more detail about available memory on the GPU, use 'gpuDevice()'. If the problem persists, reset the GPU by calling 'gpuDevice(1)'.
Error: nnet.internal.cnn.layer.FullyConnected/forward (line 73)
Z = nnet.internal.cnngpu.convolveForward2D(…
Error: nnet.internal.cnn.SeriesNetwork/forwardPropagation (line 133)
[layerOutputs{currentLayer}, memory{currentLayer}] = this.Layers{currentLayer}.forward( layerOutputs{currentLayer-1} );
Error: nnet.internal.cnn.SeriesNetwork/gradients (line 73)
[layerOutputs, memory] = this.forwardPropagation(data);
Error: nnet.internal.cnn.Trainer/train (line 58)
[gradients, miniBatchLoss, miniBatchAccuracy] = net.gradients(X, Y);
Error: trainNetwork (line 92)
trainedNet = trainer.train(trainedNet, dispatcher);
Error: samp (line 26)
net = trainNetwork(XTrain,TTrain,layers,opts);

Best Answer

It seems that the GPU memory size is small.
Instead of increasing GPU memory, please consider adjusting the value of the 'MiniBatchSize' option when using the trainNetwork function.
Decreasing this value can reduce memory consumption (and performance will vary).
Related Question