我有一个非常大的.mat文件(~ 1.3 GB),我正在尝试在我的Python代码(IPython笔记本)中加载它。我尝试了:
import scipy.io as sio
very_large = sio.loadmat('very_large.mat')
我的电脑有8GB内存,但会卡顿。我打开系统监视器,并发现内存消耗稳定增加到7GB,然后系统冻结。
我做错了什么?有什么建议或解决方法吗?
编辑:
有关数据的详细信息:以下是数据链接:http://ufldl.stanford.edu/housenumbers/ 我感兴趣的特定文件是extra_32x32.mat。 从描述中可以看出:加载.mat文件会创建2个变量:X是包含图像的4-D矩阵,y是类标签向量。要访问图像,X(:,:,:,i)给出第i个32x32 RGB图像,带有类标签y(i)。 例如,同一页面上较小的.mat文件(test_32x32.mat)在以下方式下加载:
SVHN_full_test_data = sio.loadmat('test_32x32.mat')
print("\nData set = SVHN_full_test_data")
for key, value in SVHN_full_test_data.iteritems():
print("Type of", key, ":", type(SVHN_full_test_data[key]))
if str(type(SVHN_full_test_data[key])) == "<type 'numpy.ndarray'>":
print("Shape of", key, ":", SVHN_full_test_data[key].shape)
else:
print("Content:", SVHN_full_test_data[key])
产生:
Data set = SVHN_full_test_data
Type of y : <type 'numpy.ndarray'>
Shape of y : (26032, 1)
Type of X : <type 'numpy.ndarray'>
Shape of X : (32, 32, 3, 26032)
Type of __version__ : <type 'str'>
Content: 1.0
Type of __header__ : <type 'str'>
Content: MATLAB 5.0 MAT-file, Platform: GLNXA64, Created on: Mon Dec 5 21:18:15 2011
Type of __globals__ : <type 'list'>
Content: []
mat
文件中获取所有内容吗?如果不需要,可以通过指定variable_names=['varname1','varname2']
来加载所需的变量。 - Jørgenloadmat
文档。 - hpaulj