【发布时间】:2019-11-04 09:12:17
【问题描述】:
以下代码是我如何保存 numpy 数组,保存后大约 27GB。图像数据超过200K,每个形状为(224,224,3)
hf = h5py.File('cropped data/features_train.h5', 'w')
for i,each in enumerate(features_train):
hf.create_dataset(str(i), data=each)
hf.close()
这是我用来加载数据的方法,加载需要几个小时。
features_train = np.zeros(shape=(1,224,224,3))
hf = h5py.File('cropped data/features_train.h5', 'r')
for key in hf.keys():
x = hf.get(key)
x = np.array(x)
features_train = np.append(features_train,np.array([x]),axis=0)
hf.close()
那么,对于这么大的数据量,有没有人有更好的解决方案?
【问题讨论】:
-
np,append在循环中效率低下。追加到一个列表,并在最后做一个连接。 -
一开始,我使用List来追加每个数据,然后将其转换为numpy。但这会导致内存错误。你是什么意思在最后做一个连接
标签: python-3.x numpy h5py