Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of a *.pb file in TensorFlow and how does it work?

Tags:

tensorflow

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

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

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

console log :

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

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

like image 773
Shubham Avatar asked Jul 11 '18 06:07

Shubham


People also ask

What .PB file contains?

Program file containing source code created with PureBasic; based on the BASIC programming languauge; may include variables, functions, and references to other source files.

How do I open a .PB file?

If you cannot open your PB file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a PB file directly in the browser: Just drag the file onto this browser window and drop it.

What is protobuf TensorFlow?

TensorFlow protocol buffer. Since protocol buffers use a structured format when storing data, they can be represented with Python classes. In TensorFlow, the tf. train. Example class represents the protocol buffer used to store data for the input pipeline.


1 Answers

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.

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') 

and use regular TensorFlow routine like:

sess.run(output, feed_dict={input: some_data}) 
like image 138
BiBi Avatar answered Sep 28 '22 10:09

BiBi