CS Yang
CS Yang

Reputation: 21

How tensorflow pass through a deep learning model calculation?

I am new to tensorflow and trying to figure out how tensorflow conduct the following task :

(aligned facial images) > (facenet nn model with trained weights) > (embeddings calculation)

https://www.python36.com/face-detection-matching-using-facenet/

Here listed below are codes for the above task if I understand correctly, my question is whether if the calculation was executed via sess.run() or not?

Correct me if I am wrong - (1) xxx.pb has everything for the model : layers and weights of the neural network, (2) declare images_placeholder and embeddings for the input and the output tensor of the neural network, (3) assign 'images' to input through feed_dict, and (4) execute sess.run() to pass through the neural network (xxx.pb) from input, 'feed_dict', to calculate output, 'embeddings'.

What confuse to me is there is no other expression for 'embeddings' when executing :

sess.run(embeddings, feed_dict=feed_dict)

By the way, for output tensor, does it matter if I replace name "embeddings" with "output" or any other name? It doesn't look to me there is code line for declaring "embeddings", same as "input:0".

    facenet.load_model("xxx.pb")

    # prepare placeholders for input and output tensors

    images_placeholder = tf.get_default_graph().get_tensor_by_name("input:0")
    embeddings = tf.get_default_graph().get_tensor_by_name("embeddings:0")

    # execute the tensorflow graph with "images" input

    feed_dict = { images_placeholder: images, ... }
    images_embeddings = sess.run(embeddings,feed_dict=feed_dict)

    <facenet.py>
    ......
    def load_model(model):
        model_exp = os.path.expanduser(model)
        if (os.path.isfile(model_exp)):
            print('Model filename: %s' % model_exp)
            with gfile.FastGFile(model_exp,'rb') as f:
                graph_def = tf.GraphDef()
                graph_def.ParseFromString(f.read())
                tf.import_graph_def(graph_def, name='')
        else        
            ......

Upvotes: 0

Views: 144

Answers (1)

CS Yang
CS Yang

Reputation: 21

Yes, the execution flow (1)~(4) stated above are proper.

"embeddings" can be calculated via running the following code

python face_detect_demo.py --img=images/faces.jpg

Upvotes: 0

Related Questions