【发布时间】:2018-08-15 13:45:35
【问题描述】:
内存错误
我的数据集有 70k 图像,我想通过 Conv2D 进行训练,但是当我尝试加载数据集时它会引发内存错误。我只有 4GB RAM,如何通过在HDF5 中创建数据集来通过HDF5 矩阵解决此问题?然后加载它进行训练,我想它会占用更少的内存。我尝试了一些教程来创建 HDF5 数据集,但是这个过程发生在错误发生之后。我做错了什么?如果问题不清楚,请询问。
datagen=ImageDataGenerator(rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
batch_size=28
num_classes=37
epochs=100
os.chdir("E:");
path="Dataset/One";
classes=os.listdir(path)
x=[]#Datapoints
y=[]#labels
for fol in classes:
imgfiles=os.listdir(path+u'\\'+fol);
for img in imgfiles:
im=Image.open(path+u'\\'+fol+u'\\'+img);
im=numpy.asarray(im)/255;
x.append(im)
y.append(fol)
x=numpy.array(x)
y=numpy.array(y)
#memory error####################################################
x=x.reshape((-1,100,100,1))
n=x.shape[0]
randomize=numpy.arange(n)
numpy.random.shuffle(randomize)
randomize
x=x[randomize]
y=y[randomize]
【问题讨论】:
-
这 70k 张图片的总大小有多大?
-
15 MB(100 x100) 图片
标签: python python-3.x keras hdf5 hdf5storage