Skip to content
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

Transferring Models to C++ one #1

Open
Rasoul20sh opened this issue Apr 10, 2019 · 7 comments
Open

Transferring Models to C++ one #1

Rasoul20sh opened this issue Apr 10, 2019 · 7 comments

Comments

@Rasoul20sh
Copy link

Hi Alireza and thanks for sharing your slides.
I run the codes successfully and now I want to transfer it to C++ one. As I know (And also implemented before) we can use .pbtxt and .pb files to do so by using OpenCV. But the model which david sandberg used in his work has different formats. Do you have any idea helping me transferring the code to C++ one?
Thanks again

@Alireza-Akhavan
Copy link
Owner

Hi @Rasoul20sh,

step 1:
You should Freeze graph to get a .pb file.
this articles are helpful:

and also david sandberg has a script for this job:
https://github.com/davidsandberg/facenet/blob/master/src/freeze_graph.py

step 2:

You should load pb file in opencv in c++:
something like this

int main(int argc, char **argv)
{
    cv::dnn::Net net;

    net = cv::dnn::readNetFromTensorflow("./you_model.pb");
    ...

@Rasoul20sh
Copy link
Author

Rasoul20sh commented Apr 13, 2019

Thanks @Alireza-Akhavan ,
I used sandberg's script to freeze the model (I think he also saved it in his model dir). Freeze_graph.py successfully create .pb file. But as it is mentioned in OpencvDoc we should also have a .pbtxt file to pass to cv::dnn::readNetFromTensorflow() and then use this function as bellow:

net = cv::dnn::readNetFromTensorflow("./your_model.pb" , "./mcon.pbtxt");

But freezing the model did not create any .pbtxt file.

@Rasoul20sh
Copy link
Author

Rasoul20sh commented Apr 14, 2019

Then I produce .pbtxt file using .pb file and this. I still have error with
net = cv::dnn::readNetFromTensorflow("./your_model.pb" , "./mcon.pbtxt");
Is my way the correct one??

@mehdi1661
Copy link

hi @Rasoul20sh
How did you produce .pbtxt file from .pb file?

@Rasoul20sh
Copy link
Author

hi @mehdi1661.
I used this script.

@robosina
Copy link

robosina commented Apr 17, 2019

@Rasoul20sh
As a quick answer: possibility of supporting this model in OpenCV is very low. Because OpenCV has just started to add tensorflow layers and some layers(even regular one) are not supported yet, so before trying to freeze graph, you should know which layers of your model are implemented in OpenCV. You can check by your own in OpenCV source code via this Link
I mentioned some of them in the below links:

https://github.com/opencv/opencv/blob/7ad5d219004288b3ec68c6ac0dbbb6c2e2c00e4a/modules/dnn/src/tensorflow/tf_importer.cpp#L565

https://github.com/opencv/opencv/blob/7ad5d219004288b3ec68c6ac0dbbb6c2e2c00e4a/modules/dnn/src/tensorflow/tf_importer.cpp#L748

https://github.com/opencv/opencv/blob/7ad5d219004288b3ec68c6ac0dbbb6c2e2c00e4a/modules/dnn/src/tensorflow/tf_importer.cpp#L1120

Selection_106

@Rasoul20sh
Copy link
Author

Rasoul20sh commented Apr 17, 2019

Hi @robosina and thanks for your links.
Actually I am using these models: https://drive.google.com/file/d/1EXPBSXwTaqrSC0OhUdXNmKSh9qJUQ55-/view and https://github.com/Alireza-Akhavan/deep-face-recognition/tree/master/models/20180204-160909. I am not sure I could access and modify its layers somehow OpenCV support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants