tensorflow: freeze graph fail by using the published checkpoint file: Attempting to use uninitialized value
I am using the latest Tensorflow code on Ubuntu 16.04
-
I download Inception-ResNet-v2 model from the link https://github.com/tensorflow/models/tree/master/slim
the check point file is: http://download.tensorflow.org/models/inception_resnet_v2_2016_08_30.tar.gz -
use the code below to get graph define, which output is graph.pbtxt
import tensorflow as tf
from nets import inception_resnet_v2
import numpy as np
x = tf.placeholder(shape=[1,299,299,3], dtype=tf.float32)
inception_resnet_v2 = inception_resnet_v2.inception_resnet_v2(x)
sess = tf.Session()
tf.train.write_graph(sess.graph_def, './', 'graph.pbtxt')
3, use the freeze graph tool to get .pb file.
bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=/home/scopeserver/RaidDisk/DeepLearning/mwang/Model_backup2/slim/graph.pbtxt --input_checkpoint=/home/scopeserver/RaidDisk/DeepLearning/mwang/Model_backup2/slim/inception_resnet_v2_2016_08_30.ckpt --output_graph=/tmp/frozen_graph.pb --output_node_names=InceptionResnetV2/Logits/Predictions
i get the error:
Traceback (most recent call last):
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py", line 218, in <module>
app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py", line 150, in main
FLAGS.variable_names_blacklist)
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py", line 138, in freeze_graph
variable_names_blacklist=variable_names_blacklist)
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/framework/graph_util_impl.py", line 218, in convert_variables_to_constants
returned_variables = sess.run(variable_names)
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/client/session.py", line 767, in run
run_metadata_ptr)
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/client/session.py", line 965, in _run
feed_dict_string, options, run_metadata)
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/client/session.py", line 1015, in _do_run
target_list, options, run_metadata)
File "/home/scopeserver/RaidDisk/DeepLearning/mwang/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/client/session.py", line 1035, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.FailedPreconditionError: **Attempting to use uninitialized value InceptionResnetV2/Repeat_1/block17_16/Branch_1/Conv2d_0c_7x1/biases**
[[Node: _send_InceptionResnetV2/Repeat_1/block17_16/Branch_1/Conv2d_0c_7x1/biases_0 = _Send[T=DT_FLOAT, client_terminated=true, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=4447330825950993621, tensor_name="InceptionResnetV2/Repeat_1/block17_16/Branch_1/Conv2d_0c_7x1/biases:0", _device="/job:localhost/replica:0/task:0/cpu:0"](InceptionResnetV2/Repeat_1/block17_16/Branch_1/Conv2d_0c_7x1/biases)]]
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 21 (5 by maintainers)
i figure out how to use them. the code below is to export .pbtxt file for inception_resnet_v2.
Use this .pbtxt and the published .ckpt to freeze graph, if you want to get .pb file.
if you want to load other models or get other .pbtxt files, just change the key word inception_resnet_v2 to other model name, such as inception_v2, inception_v3
the first node of .pb file is Placeholder, which is the input 4D tensor of image, such as [1,299,299,3]
you can use .ckpt for prediction as below. The endpoint is “Prediction”, But I use .pb in general, which is smaller.
the cmd to free graph for the model, pay attention to ouput node name, you can get it from .pbtxt file.
bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=/home/scopeserver/RaidDisk/DeepLearning/resnetv2.pbtxt --input_checkpoint=/home/scopeserver/RaidDisk/DeepLearning/slim/inception_resnet_v2.ckpt --output_graph=./inception_resetv2.pb --output_node_names=InceptionResnetV2/Logits/Predictions
I have the same issue on how to use my fine-tuned checkpoint files to predict the image. I will try freeze graph now. the document is very poor on this topic.
To add my 2 cents:
If the final goal is to use a pre-trained model to predict or extract features for new images, there is no need to generate intermediate .pbtxt file and consecutively freeze it. If you already know the layer names, below is the example of how to use ResNet50 model to extract features (inspired a bit from @civilman628 's answer and documentation on resnet_v1.py):
No sure why this is assigned to me, seems solved. Feel free to re-open if there is still an issue.
Hi @civilman628 could you explain in detail as to how to get the output_node_names from the .pbtxt file?