davidsandberg / facenet

Face recognition using Tensorflow
MIT License
13.72k stars 4.8k forks source link

Freeze the MTCNN graph? #218

Closed sara-dahl closed 7 years ago

sara-dahl commented 7 years ago

Hi @davidsandberg,

Is there a way to freeze the graph representing the MTCNN face detector? I'd like to use it in C++.

Thanks, Sara

MiloAnthony commented 7 years ago

Have you check out 'freeze_graph.py' in 'src' folder ? I 'd like to use it in C++ too,but still with no progress.

sara-dahl commented 7 years ago

The 'freeze_graph.py' only freezes the FaceNet model, not the one for MTCNN.

apollo-time commented 7 years ago

I had freeze the MTCNN graphs into pb files. You can download it from You can download the freeze MTCNN graphs from https://github.com/apollo-time/facenet/tree/master/model/ntcnn.

MiloAnthony commented 7 years ago

@apollo-time Thanks a lot! And how to use it ? I modified the label_image.cc in tensorflow project so I can load facenet graph as pb files. But MTCNN needs a function 'detect_face(img ....)' in Python , should I port it in C++?

apollo-time commented 7 years ago

You can download the freeze MTCNN graphs from https://github.com/apollo-time/facenet/tree/master/model/ntcnn. And load the graph from C++ like tensorflow sample.

int LoadGraph(const string & path)
{
    tensorflow::GraphDef graph_def;
    Status load_graph_status =
        ReadBinaryProto(tensorflow::Env::Default(), path, &graph_def);
    if (!load_graph_status.ok()) {
        status = tensorflow::errors::NotFound("Failed to load compute graph at '",
            path, "'");
        return status.code();
    }
    session.reset(tensorflow::NewSession(tensorflow::SessionOptions()));
    Status session_create_status = session->Create(graph_def);
    if (!session_create_status.ok()) {
        status = session_create_status;
        return status.code();
    }
    status =  Status::OK();
    return status.code();
}
MiloAnthony commented 7 years ago

@apollo-time I see , and how can I deal with the output to get face box?

sara-dahl commented 7 years ago

@apollo-time: Thank you very much for your reply and elegant work. I noticed that you've saved three separate .pb files for O-net, P-net, and R-net. The detect_face, uses these three networks, but it adds lots of calculations in between. Do you think if it is possible to generate a single network (with a single .pb file) that encompasses these calculations as well? So that we can have the image as the input and the bounding boxes as the output of this single networks.

lili25 commented 7 years ago

@apollo-time could you share how did you freeze the MTCNN graphs? From the det1.npy, det2.npy and det3.npy , I can generate the ckpt files for pnet, rnet and onet. But in my understanding, they are just the weights variables for the nets, how to get the graphs and then freeze them with the ckpt files to the .pb file ? thank you very much!

knvpk commented 7 years ago

Hey im looking to increase the response time for detecting faces for high resolution images 1080*720 for now it is taking on average of 0.4 sec to detect one image. So my question is by freezing the MTCNN graphs is there any performance improvement?

melodylovepug commented 6 years ago

@pavankumarkatakam Hey, how did you able to limit the detecting face part to 0.4 sec? I am running on a Ec2 p2.xlarge instance and having around 4 secs. Thank you very much.

wanjinchang commented 5 years ago

@apollo-time Did you try to modified the numpy caculation of mtcnn to tensorflow tensor caculation???

bansalshubh91 commented 5 years ago

@apollo-time: Thank you very much for your reply and elegant work. I noticed that you've saved three separate .pb files for O-net, P-net, and R-net. The detect_face, uses these three networks, but it adds lots of calculations in between. Do you think if it is possible to generate a single network (with a single .pb file) that encompasses these calculations as well? So that we can have the image as the input and the bounding boxes as the output of this single networks.

@sara-dahl : Were you able to make this work? Please help.

kunkun007 commented 5 years ago

@apollo-time your pb file has the same weights with npy, have you changed something or not?