Closed AI-Guru closed 4 years ago
Hi Tristan,
Yes, I couldn't save the model when I was working on it as well and I agreed with you that its related to the lambda layers. I didn't work on this project for months, so sorry about that I don't have a solution for this. I will be appreciated that if you find a solution and post it here!
Thanks!
Ah! I see!
A workaround - not a solution - is to just save the weights. That works like a charm!
Best, Tristan
Hi!
I met the problem as well and paid a lot of efforts to solve it. Luckily, I finally found that when we use Model in Keras, we must make sure that
So, to sum up, in order to save the model correctly, we can use Lambda layer with keras.backend.func or just use Dot layer to fulfil the same function.
Good luck!
@KiritoGH Thanks for sharing! I didn't maintain this repo for a very long time. Will update this once I got the chance.
Hi!
I met the problem as well and paid a lot of efforts to solve it. Luckily, I finally found that when we use Model in Keras, we must make sure that
- we always use layers to connect the network
- if we use Lambda layers, we should use keras.backend.func to fulfil our function instead of tensorflow.func.
So, to sum up, in order to save the model correctly, we can use Lambda layer with keras.backend.func or just use Dot layer to fulfil the same function.
Good luck!
Does using keras.backend means change tf.matul to K.dot??
No. You can refer to the documents for keras. We're supposed to use K.batch_dot rather than K.dot to fulfil the same function as tf.matul. An example for test is as follows.
Alternatively,you can use keras.layers.Dot.
Good luck!
@KiritoGH I really appreciate your help Thank You!!!!
Hi there!
It seems like you cannot properly save the model...
model.save("model.h5") ends up in: TypeError: can't pickle _thread.RLock objects
Any ideas? I have the feeling this has to do with the lambda layers.
Best, Tristan