tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone

Home Page:https://tensorflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Converting a .pb file to .meta in TF 1.3

amirjamez opened this issue · comments

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

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks.
Have I written custom code
OS Platform and Distribution
TensorFlow installed from
TensorFlow version
Bazel version
CUDA/cuDNN version
GPU model and memory
Exact command to reproduce

Updated my question.

It has been 14 days with no activity and the awaiting response label was assigned. Is this still an issue? Please update the label and/or status accordingly.

Nagging Awaiting Response: It has been 14 days with no activityand the awaiting response label was assigned. Is this still an issue?

Yes. It is still the same issue. No one has responded as of yet

The original poster has replied to this issue after the stat:awaiting response label was applied.

Did you try with the latest version of tensorflow?

Nagging Awaiting Response: It has been 14 days with no activityand the awaiting response label was assigned. Is this still an issue?

Nagging Awaiting Response: It has been 14 days with no activityand the awaiting response label was assigned. Is this still an issue?

Nagging Awaiting Response: It has been 14 days with no activityand the awaiting response label was assigned. Is this still an issue?

@amirjamez excuse me. Did you solve this problem? Since I tried your code and found the same issue as yours

@zhengduoru No, I did not.

Nagging Assignee @bignamehyp: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

Can you reproduce this issue with the latest tensorflow?

It has been 14 days with no activity and the awaiting response label was assigned. Is this still an issue?

It has been 30 days with no activity and the awaiting response label was assigned. Is this still an issue?

We are closing this issue for now due to lack of activity. Please comment if this is still an issue for you. Thanks!