Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get weights format from TensorFlow .pb model?

I want to reorganize the nodes of tensorflow .pb model,so I first get NodeDef from GraphDef, and get attr use NodeDef.attr().for the node of "Conv2D". I can get parameters such as strides,padding,data_format,use_cudnn_on_gpu from attr, but cann't get the weights format parameters. The language I use is c++. How to get it! Thank you!

like image 569
yiyijing Avatar asked Jul 12 '17 07:07

yiyijing


People also ask

How do I view 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.

How do I save only weights in TensorFlow?

Now to save the weights only using the simple way, you just have to call the built-in function save_weights on your model. and train it for a few epochs. This will create a folder named weights_folder and save the weights in Tensorflow native format with the name of my_weights. It is going to have 3 files.


Video Answer


1 Answers

Conv2D has two inputs: the first one is data and the second one is filter (or weights), so you can simply check the format of the second input of Conv2D. If you are using C++, you can try this:

# Assuming inputs: conv2d_node, node_map.
filter_node_name = conv2d_node.input(1)
filter_node = node_map[filter_node_name]
# You might need to check identity node here.
# Get the shape of filter_node using NodeDef.attr()
like image 110
Max Avatar answered Oct 17 '22 03:10

Max