0
我們可以保存任何創建的LSTM模型本身嗎?我相信「酸洗」是將python對象序列化到文件的標準方法。理想情況下,我想創建一個包含一個或多個函數的python模塊,這些函數或者允許我指定LSTM模型來加載或使用硬編碼的預擬合模型,以基於傳入的數據生成預測以初始化模型。PicklingError:Can not pickle <class'module'>:內建屬性查找模塊失敗
我試圖使用它,但給了我一個錯誤。我用
代碼:
# create and fit the LSTM network
batch_size = 1
model = Sequential()
model.add(LSTM(50, batch_input_shape=(batch_size, look_back, 1), stateful=True, return_sequences=True))
model.add(Dropout(0.3))
model.add(Activation('relu'))
model.add(LSTM(50, batch_input_shape=(batch_size, look_back, 1), stateful=True))
model.add(Dropout(0.3))
model.add(Activation('relu'))
model.add(Dense(1))
model.add(Activation('relu'))
model.compile(loss='mean_squared_error', optimizer='adam', metrics = ['accuracy'])
for i in range(10):
model.fit(trainX, trainY, epochs=1, batch_size=batch_size, verbose=2, shuffle=False)
model.reset_states()
with open ('sequential.pickle','wb') as f:
pickle.dump(model,f)
pickle_in = open ('sequential.pickle','rb')
model = pickle.load(pickle_in)
# make predictions
trainPredict = model.predict(trainX, batch_size=batch_size)
model.reset_states()
testPredict = model.predict(testX, batch_size=batch_size)
@coldspeed很好的幫助。讚賞。 – Ukesh