garyli1019 / pointnet-keras

Keras implementation for Pointnet
MIT License
123 stars 42 forks source link

Cannot save model #4

Closed AI-Guru closed 4 years ago

AI-Guru commented 6 years ago

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

garyli1019 commented 6 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!

AI-Guru commented 6 years ago

Ah! I see!

A workaround - not a solution - is to just save the weights. That works like a charm!

Best, Tristan

KiritoGH commented 4 years ago

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

  1. we always use layers to connect the network
  2. 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!

garyli1019 commented 4 years ago

@KiritoGH Thanks for sharing! I didn't maintain this repo for a very long time. Will update this once I got the chance.

JMParker-KR commented 4 years ago

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

  1. we always use layers to connect the network
  2. 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??

KiritoGH commented 4 years ago

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. 2020-01-08 11-27-34屏幕截图 Alternatively,you can use keras.layers.Dot.

Good luck!

JMParker-KR commented 4 years ago

@KiritoGH I really appreciate your help Thank You!!!!