【问题标题】:How tensorflow pass through a deep learning model calculation?tensorflow如何通过深度学习模型计算?
【发布时间】:2019-04-04 04:06:54
【问题描述】:

我是 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)

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

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    是的,上面所说的执行流程(1)~(4)是正确的。

    "embeddings" 可以通过运行以下代码来计算

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 2017-12-09
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      相关资源
      最近更新 更多