【问题标题】:Keras LSTM model on huge data基于海量数据的 Keras LSTM 模型
【发布时间】:2018-04-04 18:56:53
【问题描述】:
我正在尝试在具有 500 个时间戳和 6M 序列的顺序数据上构建 LSTM 模型。由于硬件配置的限制,我无法将整个数据转换为 numpy 数组。在 kears 中,如果我以块的形式创建数据并为模型提供数据,可以吗?
以下是我正在使用的方法。
For epoch in range(10):
While I<6000000:
Data1=np.array(datax[I:I+100000])
Data2=np.array(datay[I:I+100000])
Model.fit(Data1, Data2, epochs=1, batch_size=100)
I=I+100000
这个方法对吗?
【问题讨论】:
标签:
python
neural-network
keras
lstm
rnn
【解决方案1】:
是的,这个方法还可以。
您还可以为该任务创建一个生成器并只使用一个合适的。这可能会减少多次调用fit 的一些开销。
def dataReader(batch_size):
while True: #this line is just because keras needs infinite generators
while I<6000000:
Data1=np.array(datax[I:I+batch_size])
Data2=np.array(datay[I:I+batch_size])
#you could even load the data partially here from the HD
#instead of loading the entire lists datax and datay
#this will leave you more memory for having bigger models
yield (Data1,Data2)
I=I+batch_size
然后使用fit_generator:
batch_size=100
steps = 6000000 // batch_size
Model.fit_generator(dataReader(batch_size), steps_per_epoch=steps,epochs=10,...)