张量流如何通过深度学习模型计算?

时间:2018-10-31 03:16:07

标签: tensorflow

我是tensorflow的新手,试图弄清楚tensorflow如何执行以下任务:

(对齐的面部图像)>(具有经过训练的权重的facenet nn模型)>(嵌入计算)

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

如果我理解正确,下面列出的是上述任务的代码,我的问题是该计算是否通过sess.run()执行?

如果我错了,请纠正我-(1)xxx.pb具有模型的所有内容:神经网络的层和权重,(2)声明images_placeholder以及神经网络的输入和输出张量的嵌入,( 3)通过feed_dict为输入分配“图像”,然后(4)执行sess.run()从输入“ feed_dict”通过神经网络(xxx.pb),以计算输出“嵌入”。

令我感到困惑的是,执行时没有其他表达“嵌入”的表达式:

  
    

sess.run(嵌入,feed_dict = feed_dict)

  

顺便说一句,对于输出张量,是否将名称“ embedddings”替换为“ output”或任何其他名称有关系吗?在我看来,没有代码行用于声明“嵌入”,与“ 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        
            ......

1 个答案:

答案 0 :(得分:0)

是的,上述执行流程(1)〜(4)是正确的。

“嵌入”可以通过运行以下代码来计算

  
    

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