I am looking to port a object detection model trained in keras to paddlepaddle.
What I have ->
- Knowledge of the exact architecture of the model. I can implement them both in keras and in paddlepaddle
- Trained model present in keras framework
What I want ->
Trained model in paddlepaddle framework
Naive approach ->
Store the weights and biases from the keras model as a numpy and then define the model in paddlepaddle framework and load these weights into the model.
Issue ->
I am familiar with keras, and so I can easily extract the weights from the model and save it in numpy format. But I am not familiar with the paddlepaddle framework, so I don't know how to load weights into the model, one layer at a time, in form of numpy matrices.
P.S : If there is any other/better approach of doing what I am trying to do, let me know.
Thank You.
9条答案
按热度按时间8nuwlpux1#
fcipmucu2#
I tried this
Output ->
I inserted the code snippet above at line 208 in the following file ->
https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/ssd/train.py
What went wrong? I assumed that the output should have been the names of all the parameters present in my model.
mpbci0fu3#
https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/ssd/train.py
The network is defined in train_prog but not the fluid.default_main_program(). So you should write:
jljoyd4f4#
@wanghaoshuang Seems to work!!
Is there a pd_param.get() too? Because I want to see whether the weights were set properly or not
Thank You
2izufjch5#
You can get parameters from scope as numpy array.
c2e8gylq6#
Ohh great!! Will try that.
Btw, one final thing. The weights that I have ported are still trainable right? I mean just because I loaded the weights from numpy doesn't mean the default is set to not trainable or something right?
Thank You
wa7juj8i7#
Yes. They are still trainable.
tv6aics18#
@wanghaoshuang what if I want them to not be trainable? How can I control that?
ycggw6v29#
I tried the following ->
But this didn't work and weights were still getting updated. Probably because the optimizer is defined and optimizer.minimize is called before this. So I thought I need to do optimizer.minimize later
I tried
But this gave me segmentation fault. Not only that, but after I run this code, my GPU memory is occupied but I can see no python process running and so finally I had to reboot the server to get the memory back.
Then I thought maybe I should isolate the optimizer.minimize part, so I did this ->
I got the error
I hope this helps... Any idea how I can freeze the weights which I have just loaded and set into the model? @wanghaoshuang