<p dir="auto"><code class="notranslate">tensorflow.python.tools.optimize_for_inference_lib.optimize_for_inference</code> is producing an invalid graph definition. So far as I can tell this is not user error; optimizing a valid graph definition should produce a valid graph definition, so this appears to be a bug.</p>
<p dir="auto">The following code demonstrates the problem. You will need the input graph definition <a href="https://github.com/tensorflow/tensorflow/files/1001369/model.txt.gz">model.txt.gz</a>. Running the code loads the graph definition, verifies it is valid (by importing it and printing the number of nodes) then calls <code class="notranslate">optimize_for_inference</code>. We then attempt to verify the resulting graph definition but get the error</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ValueError: graph_def is invalid at node u'valid/valid_fed/model/rnn/rnn/while/multi_rnn_cell/cell_0/basic_lstm_cell/basic_lstm_cell_1/concat/axis': More inputs specified ('valid/valid_fed/model/rnn/rnn/while/Switch:1') than the op expects.."><pre class="notranslate"><code class="notranslate">ValueError: graph_def is invalid at node u'valid/valid_fed/model/rnn/rnn/while/multi_rnn_cell/cell_0/basic_lstm_cell/basic_lstm_cell_1/concat/axis': More inputs specified ('valid/valid_fed/model/rnn/rnn/while/Switch:1') than the op expects..
</code></pre></div>
<p dir="auto">The error originates from</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="tensorflow/python/framework/importer.py, line 362, in import_graph_def"><pre class="notranslate"><code class="notranslate">tensorflow/python/framework/importer.py, line 362, in import_graph_def
</code></pre></div>
<p dir="auto">The attached model definition has been manually altered to reduce the size of the (frozen) parameters but the same error occurs with the unmodified original. Attempts to reproduce this problem with a simpler graph failed. Simpler graphs can be optimized successfully. I don't know what it is about this graph that causes the failure.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import gzip

import tensorflow as tf
from google.protobuf import text_format
from tensorflow.python.tools import optimize_for_inference_lib


def verify(graph_def):
    with tf.Graph().as_default():
        tf.import_graph_def(graph_def, name=&quot;&quot;)
        print(len(tf.get_default_graph().as_graph_def().node))


def read_graph_def(path):
    graph_def = tf.GraphDef()

    with gzip.open(path, &quot;rb&quot;) as input_file:
        text_format.Merge(input_file.read(), graph_def)

    return graph_def


def optimize(input_graph_def):
    output_graph_def = optimize_for_inference_lib.optimize_for_inference(
        input_graph_def, [&quot;valid/valid_fed/model/input/x&quot;],
        [&quot;valid/valid_fed/model/output/y&quot;], tf.int32.as_datatype_enum)
    return output_graph_def


def main():
    input_graph_def = read_graph_def(&quot;model.txt.gz&quot;)
    verify(input_graph_def)
    output_graph_def = optimize(input_graph_def)
    verify(output_graph_def)


if __name__ == &quot;__main__&quot;:
    main()"><pre class="notranslate"><code class="notranslate">import gzip

import tensorflow as tf
from google.protobuf import text_format
from tensorflow.python.tools import optimize_for_inference_lib


def verify(graph_def):
    with tf.Graph().as_default():
        tf.import_graph_def(graph_def, name="")
        print(len(tf.get_default_graph().as_graph_def().node))


def read_graph_def(path):
    graph_def = tf.GraphDef()

    with gzip.open(path, "rb") as input_file:
        text_format.Merge(input_file.read(), graph_def)

    return graph_def


def optimize(input_graph_def):
    output_graph_def = optimize_for_inference_lib.optimize_for_inference(
        input_graph_def, ["valid/valid_fed/model/input/x"],
        ["valid/valid_fed/model/output/y"], tf.int32.as_datatype_enum)
    return output_graph_def


def main():
    input_graph_def = read_graph_def("model.txt.gz")
    verify(input_graph_def)
    output_graph_def = optimize(input_graph_def)
    verify(output_graph_def)


if __name__ == "__main__":
    main()
</code></pre></div>
<p dir="auto">Environment details:</p>
<ul dir="auto">
<li>Linux Ubuntu 14.04</li>
<li>TensorFlow installed from source</li>
<li>TensorFlow version: ('v1.1.0-0-g1ec6ed5', '1.1.0')</li>
<li>Bazel version: 0.4.5</li>
<li>No GPU</li>
</ul>
<p dir="auto">Env:<br>
Tensorflow-GPU 1.13.1<br>
Tensorboard 1.13.1<br>
TensorboardX 1.6<br>
Installed time: 2019/03/22<br>
Installed from PIP<br>
OS: Windows 10<br>
Python version: 3.7<br>
CUDA: 10</p>
<p dir="auto">Problem:<br>
I use command "tensorboard --logdir ... --host 127.0.0.1" to run the program, and there are many log output in the command. And not add "-v" parameter..</p>
<p dir="auto">TensorBoard 1.13.1 at <a href="http://127.0.0.1:6006" rel="nofollow">http://127.0.0.1:6006</a> (Press CTRL+C to quit)<br>
I0322 17:56:22.683215 10068 _internal.py:97] 127.0.0.1 - - [22/Mar/2019 17:56:22] "GET / HTTP/1.1" 200 -<br>
I0322 17:56:23.341972 12492 _internal.py:97] 127.0.0.1 - - [22/Mar/2019 17:56:23] "GET /font-roboto/oMMgfZMQthOryQo9n22dcuvvDin1pK8aKteLpeZ5c0A.woff2 HTTP/1.1" 200 -<br>
I0322 17:56:24.188966 10068 _internal.py:97] 127.0.0.1 - - [22/Mar/2019 17:56:24] "GET /tf-interactive-inference-dashboard/editedexample.png HTTP/1.1" 200 -<br>
...</p>
<p dir="auto">This does not appare in the previous version. I not sure whether it is a bug or a new feature.</p>