TensorFlow 中 *.pb 文件的用途是什么,它是如何工作的? [英] What is the use of a *.pb file in TensorFlow and how does it work?

查看:68
本文介绍了TensorFlow 中 *.pb 文件的用途是什么,它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些实现来创建使用此文件的人脸识别:

I am using some implementation for creating a face recognition which uses this file:

"facenet.load_model("20170512-110547/20170512-110547.pb")"

"facenet.load_model("20170512-110547/20170512-110547.pb")"

这个文件有什么用?我不确定它是如何工作的.

What is the use of this file? I am not sure how it works.

控制台日志:

Model filename: 20170512-110547/20170512-110547.pb
distance = 0.72212267

代码实际拥有者的Github链接https://github.com/arunmandal53/facematch

Github link of the actual owner of the code https://github.com/arunmandal53/facematch

推荐答案

pb 代表 protobuf.在 TensorFlow 中,protbuf 文件包含图形定义以及模型的权重.因此,您只需要一个 pb 文件即可运行给定的训练模型.

pb stands for protobuf. In TensorFlow, the protbuf file contains the graph definition as well as the weights of the model. Thus, a pb file is all you need to be able to run a given trained model.

给定一个 pb 文件,您可以按如下方式加载它.

Given a pb file, you can load it as follow.

def load_pb(path_to_pb):
    with tf.gfile.GFile(path_to_pb, "rb") as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
    with tf.Graph().as_default() as graph:
        tf.import_graph_def(graph_def, name='')
        return graph

一旦你加载了图表,你基本上可以做任何事情.例如,您可以使用

Once you have loaded the graph, you can basically do anything. For instance, you can retrieve tensors of interest with

input = graph.get_tensor_by_name('input:0')
output = graph.get_tensor_by_name('output:0')

并使用常规的 TensorFlow 例程,例如:

and use regular TensorFlow routine like:

sess.run(output, feed_dict={input: some_data})

这篇关于TensorFlow 中 *.pb 文件的用途是什么,它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆