<h3 dir="auto">Environment info</h3>
<p dir="auto">Operating System: Ubuntu 14.04 LTS 64-bit</p>
<p dir="auto">Installed version of CUDA and cuDNN: none</p>
<p dir="auto">If installed from source, provide</p>
<ol dir="auto">
<li>The commit hash (<code class="notranslate">git rev-parse HEAD</code>): <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/tensorflow/tensorflow/commit/fc9162975e52978d3af38549b570cc3cc5f0ab66/hovercard" href="https://github.com/tensorflow/tensorflow/commit/fc9162975e52978d3af38549b570cc3cc5f0ab66"><tt>fc91629</tt></a></li>
<li>The output of <code class="notranslate">bazel version</code></li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Build label: 0.3.0
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jun 10 11:38:23 2016 (1465558703)
Build timestamp: 1465558703
Build timestamp as int: 1465558703"><pre class="notranslate"><code class="notranslate">Build label: 0.3.0
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jun 10 11:38:23 2016 (1465558703)
Build timestamp: 1465558703
Build timestamp as int: 1465558703
</code></pre></div>
<h3 dir="auto">Steps to reproduce</h3>
<ol dir="auto">
<li>Copy the IPython Notebook for Assignment 6 of Udacity's deep learning course (<a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/6_lstm.ipynb">here</a>)</li>
<li>Change <code class="notranslate">saved_sample_output = tf.Variable(tf.zeros([1, num_nodes]))</code> to <code class="notranslate">saved_sample_output = tf.Variable(tf.zeros([1, num_nodes]), name="saved_sample_output")</code></li>
<li>Modify the code like so:</li>
</ol>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="with tf.Session(graph=graph) as session:
  tf.initialize_all_variables().run()
  print('Initialized')
  mean_loss = 0
  # code omitted (no changes)
  # new code below:
  saver = tf.train.Saver(tf.all_variables())
  saver.save(session, '/home/me/Documents/checkpoint.ckpt', write_meta_graph=False)
  tf.train.write_graph(graph.as_graph_def(), '/home/me/Documents', 'graph.pb')"><pre class="notranslate"><span class="pl-k">with</span> <span class="pl-s1">tf</span>.<span class="pl-v">Session</span>(<span class="pl-s1">graph</span><span class="pl-c1">=</span><span class="pl-s1">graph</span>) <span class="pl-k">as</span> <span class="pl-s1">session</span>:
  <span class="pl-s1">tf</span>.<span class="pl-en">initialize_all_variables</span>().<span class="pl-en">run</span>()
  <span class="pl-en">print</span>(<span class="pl-s">'Initialized'</span>)
  <span class="pl-s1">mean_loss</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
  <span class="pl-c"># code omitted (no changes)</span>
  <span class="pl-c"># new code below:</span>
  <span class="pl-s1">saver</span> <span class="pl-c1">=</span> <span class="pl-s1">tf</span>.<span class="pl-s1">train</span>.<span class="pl-v">Saver</span>(<span class="pl-s1">tf</span>.<span class="pl-en">all_variables</span>())
  <span class="pl-s1">saver</span>.<span class="pl-en">save</span>(<span class="pl-s1">session</span>, <span class="pl-s">'/home/me/Documents/checkpoint.ckpt'</span>, <span class="pl-s1">write_meta_graph</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
  <span class="pl-s1">tf</span>.<span class="pl-s1">train</span>.<span class="pl-en">write_graph</span>(<span class="pl-s1">graph</span>.<span class="pl-en">as_graph_def</span>(), <span class="pl-s">'/home/me/Documents'</span>, <span class="pl-s">'graph.pb'</span>)</pre></div>
<ol dir="auto">
<li>Run.</li>
<li>Verify that <code class="notranslate">checkpoint.ckpt</code> and <code class="notranslate">graph.pb</code> have been successfully created in the directory.</li>
<li>In the tensorflow source directory, run:</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="bazel build tensorflow/python/tools:freeze_graph &amp;&amp; bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=/home/me/Documents/graph.pb --input_checkpoint=/home/me/Documents/checkpoint.ckpt --output_graph=/home/me/Documents/frozen_graph.pb --output_node_names=saved_sample_output"><pre class="notranslate"><code class="notranslate">bazel build tensorflow/python/tools:freeze_graph &amp;&amp; bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=/home/me/Documents/graph.pb --input_checkpoint=/home/me/Documents/checkpoint.ckpt --output_graph=/home/me/Documents/frozen_graph.pb --output_node_names=saved_sample_output
</code></pre></div>
<h3 dir="auto">What have you tried?</h3>
<p dir="auto">Checked the <code class="notranslate">graph.pb</code> file to make sure that node had actually been named properly. Seems like it was:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# other stuff
node {
  name: &quot;saved_sample_output&quot;
  op: &quot;Variable&quot;
  attr {
    key: &quot;container&quot;
    value {
      s: &quot;&quot;
    }
  }
  attr {
    key: &quot;dtype&quot;
    value {
      type: DT_FLOAT
    }
  }
  attr {
    key: &quot;shape&quot;
    value {
      shape {
        dim {
          size: 1
        }
        dim {
          size: 64
        }
      }
    }
  }
  attr {
    key: &quot;shared_name&quot;
    value {
      s: &quot;&quot;
    }
  }
}
# etc."><pre class="notranslate"><code class="notranslate"># other stuff
node {
  name: "saved_sample_output"
  op: "Variable"
  attr {
    key: "container"
    value {
      s: ""
    }
  }
  attr {
    key: "dtype"
    value {
      type: DT_FLOAT
    }
  }
  attr {
    key: "shape"
    value {
      shape {
        dim {
          size: 1
        }
        dim {
          size: 64
        }
      }
    }
  }
  attr {
    key: "shared_name"
    value {
      s: ""
    }
  }
}
# etc.
</code></pre></div>
<p dir="auto">I'm pretty much stumped with this one since <a href="https://stackoverflow.com/questions/38958662/tensorflow-what-are-the-output-node-names-for-freeze-graph-py-in-the-model-wi" rel="nofollow">this</a> issue on StackOverflow says to pass in a name parameter for the node you want, which is what I did, to no avail (even without the name parameter, it still gave the same error).<br>
<strong>Edit:</strong> Got freeze_graph to run successfully with the <code class="notranslate">sample_prediction</code> node (changed <code class="notranslate">sample_prediction = tf.nn.softmax(tf.nn.xw_plus_b(sample_output, w, b))</code> to <code class="notranslate">sample_prediction = tf.nn.softmax(tf.nn.xw_plus_b(sample_output, w, b), name="sample_prediction")</code>). However, I still haven't figured out why that worked, and this didn't.</p>
<h3 dir="auto">Logs or other output that would be helpful</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py&quot;, line 134, in &lt;module&gt;
    tf.app.run()
  File &quot;/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/platform/app.py&quot;, line 30, in run
    sys.exit(main(sys.argv))
  File &quot;/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py&quot;, line 131, in main
    FLAGS.output_graph, FLAGS.clear_devices, FLAGS.initializer_nodes)
  File &quot;/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py&quot;, line 120, in freeze_graph
    sess, input_graph_def, output_node_names.split(&quot;,&quot;))
  File &quot;/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/framework/graph_util.py&quot;, line 232, in convert_variables_to_constants
    inference_graph = extract_sub_graph(input_graph_def, output_node_names)
  File &quot;/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/framework/graph_util.py&quot;, line 156, in extract_sub_graph
    assert d in name_to_node_map, &quot;%s is not in graph&quot; % d
AssertionError: saved_sample_output is not in graph"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py", line 134, in &lt;module&gt;
    tf.app.run()
  File "/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/platform/app.py", line 30, in run
    sys.exit(main(sys.argv))
  File "/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py", line 131, in main
    FLAGS.output_graph, FLAGS.clear_devices, FLAGS.initializer_nodes)
  File "/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/tools/freeze_graph.py", line 120, in freeze_graph
    sess, input_graph_def, output_node_names.split(","))
  File "/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/framework/graph_util.py", line 232, in convert_variables_to_constants
    inference_graph = extract_sub_graph(input_graph_def, output_node_names)
  File "/home/me/tf_m/tensorflow/bazel-bin/tensorflow/python/tools/freeze_graph.runfiles/org_tensorflow/tensorflow/python/framework/graph_util.py", line 156, in extract_sub_graph
    assert d in name_to_node_map, "%s is not in graph" % d
AssertionError: saved_sample_output is not in graph
</code></pre></div>
<p dir="auto">When a conv2d operator has a stride greater than the kernel size, the following error is thrown:<br>
<code class="notranslate">ValueError: ('stride must be less than or equal to filter size', 'stride: [2x2] filter: [Dimension(1)xDimension(1)]')</code><br>
This makes implementing the 1x1 convolutions used to reduce spatial resolution in several papers (MSRA 2015 among others) awkward. Also, a convolution with stride greater than kernel size may be unusual but is it still well defined. Fixing this may be as simple as removing this assertion.<br>
Thanks to everyone who developed TensorFlow, it's a fascinating tool.</p>