Skip to content

Converting a .pb file to .meta in TF 1.3 #15292

@amirjamez

Description

@amirjamez

Using tf.slim's pre-trained models we can export_inference_graph to generate a .pb file for a given .ckpt, say inception_v3. Is there a way to generate .meta file of inception_v3 using these two files as well?

My specific use case is that I need to see the pre-trained weights if inception in each tensor (tf.variable) and don't know any other way to retrieve other using .meta and .ckpt to do so and I lack .meta here:

#retrieve a pre-trained model
sess = tf.Session()
saver = tf.train.import_meta_graph('./model.meta')
saver.restore(sess,'./model.ckpt')

Steps to reproduce:

I used the instution in export_inference_graph and generated a .pb file, then I exported the .meta file as bellow:

sess=tf.Session()
INCEPTION_PB='./inception_v3_inf_graph.pb'
    
f=gfile.FastGFile(INCEPTION_PB,'rb')
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_= tf.import_graph_def(graph_def,name='')
meta_graph_def = tf.train.export_meta_graph(filename='./inception.meta')

However, this results in a .meta file without collections, thus can not initialized:

>>> saver = tf.train.import_meta_graph('./inception.meta')
INFO:tensorflow:Saver not created because there are no variables in the graph to restore
 >>> saver.restore(sess,'../../inception_v3.ckpt')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'restore'

What is the problem here? I guess it would be nice this conversion feature is added to TF.

Info:
Have I written custom code: Not much except these above.
OS Platform and Distribution: Ubuntu 14.04.3 - 3.19.0-25-generic
TensorFlow installed from: pip installation
TensorFlow version - v1.3
Bazel version: v5.4
CUDA/cuDNN version: v6.0
GPU model and memory: NVIDIA GeForce GTX 1060 6GB - memoryClockRate (GHz) 1.7845

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions