python – 使用Keras fit_generator和datagen.flow时出现内存错
发布时间:2020-12-20 13:17:15 所属栏目:Python 来源:网络整理
导读:我想在Keras中使用带有 ImageGenerator类的datagen.flow.我收到以下内存错误: Traceback (most recent call last):File "scratch_6.py",line 284,in modulehistory = model.fit_generator(datagen.flow(train_X,train_y,batch_size=batch_size,save_to_dir=
我想在Keras中使用带有
ImageGenerator类的datagen.flow.我收到以下内存错误:
Traceback (most recent call last): File "scratch_6.py",line 284,in <module> history = model.fit_generator(datagen.flow(train_X,train_y,batch_size=batch_size,save_to_dir='test_RA',save_format='png'),File "/usr/local/lib/python3.5/dist- packages/keras/preprocessing/image.py",line 455,in flow save_format=save_format) File "/usr/local/lib/python3.5/dist- packages/keras/preprocessing/image.py",line 764,in __init__ self.x = np.asarray(x,dtype=K.floatx()) File "/usr/local/lib/python3.5/dist-packages/numpy/core/numeric.py",line 531,in asarray return array(a,dtype,copy=False,order=order) MemoryError 我有128GB的RAM可用.我试过减少批量大小,但没有变化.任何帮助赞赏.谢谢. 解决方法
这是所有深度学习算法的常见问题,其中数据集的大小非常大.
因此,对于这类问题,我们无法将所有数据加载到RAM中,因为计算和保存模型RAM内存需要大量的空间.同时,当我们将输入数据从int类型转换为floot时,它将需要输入图像的4倍空间. 所以解决这个问题的方法是对图像进行预处理,并完成数据增加并将整个数据保存到hdf5数据库中并存储到硬盘中,并且批量获取数据的时间逐批加载并训练模型,可能需要很长时间,但它不会完全消耗内存. 谢谢注:Kunal (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |