内存不足 - 默认 matlab 数据库和代码

Out of memory - default matlab database and code

我正在使用 matlab 示例学习 nn 工具箱,但我总是遇到错误

Out of memory. Type HELP MEMORY for your options. Error in test2 (line 10) xTest = zeros(inputSize,numel(xTestImages));

这是我的简单代码

% Get the number of pixels in each image
imageWidth = 28;
imageHeight = 28;
inputSize = imageWidth*imageHeight;

% Load the test images
[xTestImages, outputs] = digittest_dataset;

% Turn the test images into vectors and put them in a matrix
xTest = zeros(inputSize,numel(xTestImages));
for i = 1:numel(xTestImages)
    xTest(:,i) = xTestImages{i}(:);
end

代码是根据 mathwork example(但我正在尝试建立自己的自定义网络)。我重新安装了 matlab,最大 java RAM 存储,清理了一些磁盘 space 并延迟了神经网络的其余部分。还是行不通。有解决此问题的想法吗?

如上所写,行:

xTest = zeros(inputSize,numel(xTestImages)); # xTestImages is 1x5000

将产生大小为 28^2*5000= 3,920e6 个元素的矩阵。每个元素都有双精度(8 字节),因此矩阵将消耗大约 30 MB...

您说过,命令 memory 显示以下内容:

Maximum possible array: 29 MB (3.054e+07 bytes) 
* Memory available for all arrays: 467 MB (4.893e+08 bytes) 
** Memory used by MATLAB: 624 MB (6.547e+08 bytes) 
Physical Memory (RAM): 3067 MB (3.216e+09 bytes) 

所以第一行显示了一个单一数组的限制。

所以有几点需要考虑:

我知道这不会解决问题,但也许它会帮助您同时继续工作:您可以创建适用于您的测试用例的单精度矩阵。创建矩阵时,只需将 single 作为第二个选项传递即可。

内存不足是由 Levenberg–Marquardt 算法造成的 - 当数据很大时,它会为计算创建巨大的雅可比矩阵。