chensvm / A-Dual-Stage-Attention-Based-Recurrent-Neural-Network-for-Time-Series-Prediction

115 stars 35 forks source link

How to save the model? #1

Open myvrml opened 6 years ago

myvrml commented 6 years ago

Hi, Chen:

I download your code and run it on my computer successfully. Now , I want to save the model, I edit the code :

model.fit([input_X_train,input_Y_train,s0_train,h0_train,s_de0_train,h_de0_train],label_Y_train,epochs=epochs,batch_size=batch_size,validation_split=0.2, callbacks=[ModelCheckpoint(filepath='{val_loss:.4f}-weights.{epoch:02d}.hdf5', monitor='val_loss', save_best_only=False, mode='min',period=1)]).

But it raised an error: TypeError: can't pickle _thread.lock objects.

Whole error information: 22656/22708 [============================>.] - ETA: 0s - loss: 21343456.8136 - mean_squared_error: 21343456.8136C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'input_3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'input_2:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_1/TensorArrayReadV3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'lstm_1/while/Exit_3:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_1_1/TensorArrayReadV3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'lstm_1_1/while/Exit_3:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_1_2/TensorArrayReadV3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'lstm_1_2/while/Exit_3:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_1_3/TensorArrayReadV3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'lstm_1_3/while/Exit_3:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_1_4/TensorArrayReadV3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'lstm_1_4/while/Exit_3:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_1_5/TensorArrayReadV3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'lstm_1_5/while/Exit_3:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_1_6/TensorArrayReadV3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'lstm_1_6/while/Exit_3:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_1 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_1_7/TensorArrayReadV3:0' shape=(?, 20) dtype=float32>, <tf.Tensor 'lstm_1_7/while/Exit_3:0' shape=(?, 20) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'input_4:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'input_5:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_2/TensorArrayReadV3:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'lstm_2/while/Exit_3:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_2_1/TensorArrayReadV3:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'lstm_2_1/while/Exit_3:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_2_2/TensorArrayReadV3:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'lstm_2_2/while/Exit_3:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_2_3/TensorArrayReadV3:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'lstm_2_3/while/Exit_3:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_2_4/TensorArrayReadV3:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'lstm_2_4/while/Exit_3:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_2_5/TensorArrayReadV3:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'lstm_2_5/while/Exit_3:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_2_6/TensorArrayReadV3:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'lstm_2_6/while/Exit_3:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py:2362: UserWarning: Layer lstm_2 was passed non-serializable keyword arguments: {'initial_state': [<tf.Tensor 'lstm_2_7/TensorArrayReadV3:0' shape=(?, 30) dtype=float32>, <tf.Tensor 'lstm_2_7/while/Exit_3:0' shape=(?, 30) dtype=float32>]}. They will not be included in the serialized model (and thus will be missing at deserialization time). str(node.arguments) + '. They will not be included ' Traceback (most recent call last): File "D:\sunfan\work\python\code\DARNN\dual_attention.py", line 214, in model.fit([input_X_train,input_Y_train,s0_train,h0_train,s_de0_train,h_de0_train],label_Y_train,epochs=epochs,batch_size=batch_size,validation_split=0.2, callbacks=[ModelCheckpoint(filepath='{val_loss:.4f}-weights.{epoch:02d}.hdf5', monitor='val_loss', save_best_only=False, mode='min',period=1)]) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 1669, in fit validation_steps=validation_steps) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 1226, in _fit_loop callbacks.on_epoch_end(epoch, epoch_logs) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\callbacks.py", line 76, in on_epoch_end callback.on_epoch_end(epoch, logs) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\callbacks.py", line 429, in on_epoch_end self.model.save(filepath, overwrite=True) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2574, in save save_model(self, filepath, overwrite, include_optimizer) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py", line 111, in save_model 'config': model.get_config() File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2415, in get_config return copy.deepcopy(config) File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 215, in _deepcopy_list append(deepcopy(a, memo)) File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 220, in _deepcopy_tuple y = [deepcopy(a, memo) for a in x] File "C:\ProgramData\Anaconda3\lib\copy.py", line 220, in y = [deepcopy(a, memo) for a in x] File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 220, in _deepcopy_tuple y = [deepcopy(a, memo) for a in x] File "C:\ProgramData\Anaconda3\lib\copy.py", line 220, in y = [deepcopy(a, memo) for a in x] File "C:\ProgramData\Anaconda3\lib\copy.py", line 180, in deepcopy y = _reconstruct(x, memo, rv) File "C:\ProgramData\Anaconda3\lib\copy.py", line 280, in _reconstruct state = deepcopy(state, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 180, in deepcopy y = _reconstruct(x, memo, rv) File "C:\ProgramData\Anaconda3\lib\copy.py", line 280, in _reconstruct state = deepcopy(state, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 180, in deepcopy y = _reconstruct(x, memo, *rv) File "C:\ProgramData\Anaconda3\lib\copy.py", line 280, in _reconstruct state = deepcopy(state, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 150, in deepcopy y = copier(x, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 240, in _deepcopy_dict y[deepcopy(key, memo)] = deepcopy(value, memo) File "C:\ProgramData\Anaconda3\lib\copy.py", line 169, in deepcopy rv = reductor(4) TypeError: can't pickle _thread.lock objects

How to fix the problem or another way to save the model?Thank u!

chuanchuan12138 commented 5 years ago

I've got the same problem recently , could you please tell me how did you solve it?

HUHU69 commented 4 years ago

I've got the same problem recently , could you please tell me how did you solve it?