加载所有.h5文件并将其提供给model.fit()

时间:2019-10-29 11:10:00

标签: python tensorflow keras lstm hdf5

比方说,我有10个.h5分隔的文件来训练我的LSTM模型,还有5个用于测试。

我的问题是如何使用model.fit()加载所有.h5文件并将其提供给我的模型。

让我们先从我的LSTM模型开始,然后仅加载一个文件进行训练:

model= Sequential()

model.add(LSTM(units = 50, return_sequences = True, input_shape = (None, 50)))
model.add(Dropout(0.2))

model.add(LSTM(units = 50, return_sequences = True))
model.add(Dropout(0.2))

model.add(LSTM(units = 50, return_sequences = True))
model.add(Dropout(0.2))

model.add(LSTM(units = 50))
model.add(Dropout(0.2))

model.add(Dense(units = 1))

model.compile(optimizer = 'adam', loss = 'mean_squared_error')

x_train = HDF5Matrix('path_to_X_train_h5_file', 'X', start=0, end=10)
y_train = HDF5Matrix('path_to_Y_train_h5_file', 'Y', start=0, end=10)

x_test = HDF5Matrix('path_to_X_test_h5_file', 'X', start=0, end=10)
y_test = HDF5Matrix('path_to_Y_test_h5_file', 'Y', start=0, end=10)

model.fit(x_train, y_train, validation_data=(x_test, y_test), epochs=2, batch_size=256, verbose=1)

现在我应该如何加载所有.h5文件以适合模型,正确的方法是什么?

PS:请注意,.h5文件中的数据集具有不同的形状!这就是为什么我将Lone放在输入LSTM层的“ input_shape”中。

0 个答案:

没有答案