title: Inference optimization for multiple inputs/outputs custom Estimator
body: <p>I have a custom Estimator. I'm trying to optimize this Estimator for inference (freeze + optimize). </p>
  
  <p>Here is what I tried to add in <code>model_fn()</code> :</p>
  
  <pre><code>input_tensors = [input_1, input_2, input_3]
  output_tensors = [output_1, output_2, output_3, output_4]
  
  tmp_g = tf.get_default_graph().as_graph_def()
  
  from tensorflow.python.tools.optimize_for_inference_lib import optimize_for_inference
  
  with tf.Session() as sess:
      sess.run(tf.global_variables_initializer())
      tmp_g = tf.graph_util.convert_variables_to_constants(sess, tmp_g, [n.name[:-2] for n in output_tensors])
      dtypes = [n.dtype for n in input_tensors]
  
      tmp_g = optimize_for_inference(
                  tmp_g,
                  [n.name[:-2] for n in input_tensors],
                  [n.name[:-2] for n in output_tensors],
                  [dtype.as_datatype_enum for dtype in dtypes],
                  False)
  
  
      output_1, output_2, output_3, output_4 = tf.import_graph_def(tmp_g, input_map={n.name[:-2] + ':0': n for n in input_tensors}, return_elements=['output_1', 'output_2', 'output_3', 'output_4 '])
      from tensorflow.python.estimator.model_fn import EstimatorSpec
  
      return EstimatorSpec(mode=mode, predictions={
                  "output_1": output_1[0],
                  "output_2": output_2[0],
                  "output_3": output_3[0],
                  "output_4": output_4[0]
          })
  </code></pre>
  
  <p>However, when <code>import_graph_def</code> is called, I receive following error :</p>
  
  <blockquote>
    <p>ValueError: Node 'bert/embeddings/ExpandDims': Connecting to invalid
    output 1 of source node IteratorGetNext which has 1 outputs</p>
  </blockquote>
  
  <p>(My inputs are connected to a BERT model).</p>
  
  <hr>
  
  <p><strong>Any idea from where it come from ? And how to fix this ?</strong></p>