<h3 dir="auto">System information</h3>
<ul dir="auto">
<li><strong>Have I written custom code (as opposed to using a stock example script provided in TensorFlow)</strong>: Yes</li>
<li><strong>OS Platform and Distribution (e.g., Linux Ubuntu 16.04)</strong>: Linux centos 7</li>
<li><strong>TensorFlow installed from (source or binary)</strong>: with pip</li>
<li><strong>TensorFlow version (use command below)</strong>: 1.5.0 (vs 1.4.1)</li>
<li><strong>Python version</strong>: 2.7.5</li>
<li><strong>Bazel version (if compiling from source)</strong>: No</li>
<li><strong>GCC/Compiler version (if compiling from source)</strong>: No</li>
<li><strong>CUDA/cuDNN version</strong>: No</li>
<li><strong>GPU model and memory</strong>: No</li>
<li><strong>Exact command to reproduce</strong>:</li>
</ul>
<p dir="auto">Clone the tensorflow/models repo.<br>
then</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cd models/research/slim/
python export_inference_graph.py \
  --model_name=inception_v1 \
  --image_size=224 \
  --output_file=/tmp/inception_v1.pb"><pre class="notranslate"><code class="notranslate">cd models/research/slim/
python export_inference_graph.py \
  --model_name=inception_v1 \
  --image_size=224 \
  --output_file=/tmp/inception_v1.pb
</code></pre></div>
<p dir="auto">Then freeze the graph :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cd tensorflow/tensorflow/python/tools/
python freeze_graph.py \
--input_graph /tmp/inception_v1.pb \
--input_checkpoint /tmp/inception_v1.ckpt \
--output_graph /tmp/inception_v1_frozen.pb \
--input_binary True \
--output_node_names &quot;InceptionV1/Logits/Predictions/Reshape_1&quot;"><pre class="notranslate"><code class="notranslate">cd tensorflow/tensorflow/python/tools/
python freeze_graph.py \
--input_graph /tmp/inception_v1.pb \
--input_checkpoint /tmp/inception_v1.ckpt \
--output_graph /tmp/inception_v1_frozen.pb \
--input_binary True \
--output_node_names "InceptionV1/Logits/Predictions/Reshape_1"
</code></pre></div>
<p dir="auto">Then in python do :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import tensorflow as tf
from tensorflow.core.framework import graph_pb2
from tensorflow.python.platform import gfile
import tensorflow.tools.graph_transforms as graph_transforms
graph = graph_pb2.GraphDef()
with open(&quot;/tmp/inception_v1_frozen.pb&quot;, 'rb') as f:
    s = f.read()
    graph.ParseFromString(s)
graph = graph_transforms.TransformGraph(graph,
            [&quot;input&quot;], # inputs nodes
            [&quot;InceptionV1/Logits/Predictions/Reshape_1&quot;], # outputs nodes
            ['fold_constants()'])
with gfile.FastGFile(&quot;/tmp/inception_v1_frozen&quot;+&quot;_optimized.pbtxt&quot;, &quot;w&quot;) as f:
    f.write(str(graph))"><pre class="notranslate"><code class="notranslate">import tensorflow as tf
from tensorflow.core.framework import graph_pb2
from tensorflow.python.platform import gfile
import tensorflow.tools.graph_transforms as graph_transforms
graph = graph_pb2.GraphDef()
with open("/tmp/inception_v1_frozen.pb", 'rb') as f:
    s = f.read()
    graph.ParseFromString(s)
graph = graph_transforms.TransformGraph(graph,
            ["input"], # inputs nodes
            ["InceptionV1/Logits/Predictions/Reshape_1"], # outputs nodes
            ['fold_constants()'])
with gfile.FastGFile("/tmp/inception_v1_frozen"+"_optimized.pbtxt", "w") as f:
    f.write(str(graph))
</code></pre></div>
<h3 dir="auto">Describe the problem</h3>
<p dir="auto">I am using the graph_transform to fold constants in by graph saved as .pb.<br>
When I use the fold_constants() transformation, some inputs of some nodes are renamed but not the corresponding nodes in the whole graph. So the graph is no longer valid...</p>
<p dir="auto">I have an "input" placeholder in the graph.<br>
And the node connected to this placeholder as an input name "input:0" instead of "input".</p>
<p dir="auto">With the version 1.4.1 of tensorflow, I didn't have this issue.</p>
<p dir="auto">To reproduce, follow the instructions below, and take a look to the /tmp/inception_v1_frozen_optimized.pbtxt graph. And search le node named "input" it is the input placeholder. Then search node which has an input named "input:0". This name ("input:0") is node a node of the graph.</p>
<p dir="auto"><strong>System information</strong></p>
<ul dir="auto">
<li>Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No</li>
<li>OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04</li>
<li>TensorFlow installed from (source or binary): source</li>
<li>TensorFlow version (use command below): 1.12.0 (tensorflow-gpu, tensorflow-base)</li>
<li>Python version: 3.6.8</li>
<li>Bazel version (if compiling from source): 0.21.0</li>
<li>GCC/Compiler version (if compiling from source): 5.4.0 20160609</li>
<li>CUDA/cuDNN version: 7.1.2</li>
<li>GPU model and memory: GeForce GTX 1080, 8GB</li>
</ul>
<p dir="auto"><strong>Describe the current behavior</strong><br>
Following the <a href="https://gist.github.com/carlthome/6ae8a570e21069c60708017e3f96c9fd">https://gist.github.com/carlthome/6ae8a570e21069c60708017e3f96c9fd</a> tutorial, which is based on <a href="https://www.tensorflow.org/xla/tfcompile" rel="nofollow">https://www.tensorflow.org/xla/tfcompile</a>, all the compilation steps succeed. I am also able to invoke the compiled graph, producing correct prediction results. A non-compiled predict of a single image using RestNet50 takes 5ms, a compiled version takes ~140ms.</p>
<p dir="auto">Note: I have ran ./configure via a terminal to use force CUDA support (such option is not accepted in the example).</p>
<p dir="auto"><strong>Describe the expected behavior</strong><br>
The compiled version prediction of a single image should be as fast as a non-compiled prediction. I suspect the compiled graph uses CPU for the inference.</p>
<p dir="auto"><strong>Code to reproduce the issue</strong><br>
Follow the <a href="https://gist.github.com/carlthome/6ae8a570e21069c60708017e3f96c9fd">https://gist.github.com/carlthome/6ae8a570e21069c60708017e3f96c9fd</a> tutorial. To evaluate the compiled and the non-compiled graph prediction of a single image duration, add these two lines to the end of the notebook:</p>
<p dir="auto"><code class="notranslate">%timeit -n 20 predict(x)</code><br>
<code class="notranslate">%timeit -n 20 model.predict(x)</code></p>