tensorflow: Bug - freeze_graph producing invalid graph_def in tensorflow 1.4
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- TensorFlow installed from (source or binary): binary
- TensorFlow version (use command below): release 1.4
- Python version: 3.5
- Bazel version (if compiling from source): -
- GCC/Compiler version (if compiling from source): -
- CUDA/cuDNN version: 8/6
- GPU model and memory: GTX 970, 4GB
- Exact command to reproduce:
- Download dbg.zip (contains
graph.pbtxt, checkpoint and the resultingfrozen_model.pbgenerated on my machine .) - Unzip and open terminal in the unzipped folder
- Run <tensorflow_root>/python/tools/freeze_graph.py --input_graph=graph.pbtxt --input_binary=False --input_checkpoint=model.ckpt-1 --output_node_names=softmax_tensor --output_graph=frozen_model_test.pb --clear_devices=True
- Start python, attempt to import the frozen graph:
import tensorflow as tf
from tensorflow.python.platform import gfile
with gfile.FastGFile('frozen_model_test.pb','rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
Describe the problem
Trying to import the graph, I get this error:
ValueError: graph_def is invalid at node ‘IsVariableInitialized’: Input tensor ‘global_step:0’ Cannot convert a tensor of type int64 to an input of type int64_ref.
The error is raised in tf.import_graph_def(graph_def, name=''). The dump of str(graph_def) can be seen in this text file: graph_def_dbg.txt
The error happens sine the upgrade to TF 1.4, with TF 1.3 the graph freezing and importing works as expected.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (3 by maintainers)
Same as @dratini6 . I’ve solved this issue by adding “global_step” in the black list on tf.graph_util.convert_variables_to_constants method.
Hello @GPhilo, I solved my issue now by defining the initial values of the problematic variables as additional placeholders. This means I have to feed the initializing values additionally when using the model, but at least this got the model usable. The initializers are the init_states variables in https://github.com/asoehlke/neuronal-music-accompanist-bach/blob/master/MusicAccompanistInferenceGraph.ipynb.
With this change, freeze_graph works without any blacklisted variables.