-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to load trained DNN (in C++) for face recognition in Python #483
Comments
The network definitions used in dnn_metric_learning_on_images_ex.cpp and the dnn_face_recogition_ex.cpp are different. That's why you are getting this error. If you want to use the same python code to load a model it's got to be a model that uses the same network definition as the face recognition code. |
My point is quite different. In fact, the dnn_face_recognition_ex.cpp is able to deserialize and load the model. However, the Python code is failing at even loading a model. |
Does the |
There is no way dnn_face_recogition_ex.cpp is loading the model file generated by dnn_metric_learning_on_images_ex.cpp since the network definitions are different. Specifically they are different in the input layer which is what your error message says. So you must have mixed up files if you think this is happening. There isn't anything magic about the python API. It's just calling the C++ code. |
Okay, we can forget about dnn_face_recognition_ex.cpp for the moment. The error message that I have generated is clearly from running the Python code! Do I have to use some other API in Python for loading a self trained model? |
|
So I'll have to change the network accordingly for my use at python/src file, right? Thanks! |
Yes. The network architecture must match what is declared in the code.
|
Right, it worked! On a side note, could we create an API in Python to instantiate a network configuration? It would be neater to specify a certain config and then load the corresponding learnt model. We probably need to find a way to make a data structure that encodes the layers, and then it could be done? |
No, the point of this tooling is to make a nice C++ API for deep learning.
Unfortunately, most C++ language concepts don't translate into python. So
there isn't any nice way to do this.
|
hi@davisking, could you please add a new version of dnn_metric_learning_on_images_ex.cpp |
"Also, the dnn_metric_learning_on_images_ex.cpp example shows how to train this network. |
@davisking,I have modified the network architecture and got a model (trained by my dataset) which can be used by dnn_face_recognition_ex.cpp and python API. My question is my dataset has a small volume and my model does not work very well, can i just train the model base your published dlib_face_recognition_resnet_model_v1 model, but not start from 0 ? |
You could do that. If you have a small amount of data though you should
just train a linear classifier on the final output rather than trying to
modify the whole network.
|
Sorry @davisking , maybe i didn't speak very clearly. I just modified the network architecture in dnn_metric_learning_on_images_ex.cpp and train my model with my dataset. My question is that may i load the dlib_face_recognition_resnet_model_v1.dat you have published to net and then continue my trainning with my custom dataset? |
No, not if you changed the network architecture to something else. |
So, is there any hint or example can i refer to ? |
@anirudt How did you change the network configuration on dnn_face_recognition_ex.cpp so that it worked with dlib.face_recognition_model_v1("metric_network_renset.dat")? Thanks so much for the help! |
You can just change the structure of the net from |
I trained a DNN as given in the examples/dnn_metric_learning_on_images_ex.cpp file with a custom image dataset. This saved a file as
metric_network_renset.dat
. However, while trying to load the model in Python using the APIdlib.face_recognition_model_v1("metric_network_renset.dat")
, it gives the following error:However, after trying in C++, the deserializing and loading of the model is working perfectly, as in examples/dnn_face_recognition_ex.cpp.
Basically, I would want to know how to load a self-trained network in Python for post-processing, whether it is possible, and/or if
face_recognition_model_v1()
is the right API for it.The text was updated successfully, but these errors were encountered: