title: Tensorflow segmentation fault running multirow tensor in C++ api
body: <p>We are developing a method to load and run a .pb file within our code and have run into an odd segmentation fault which we cannot figure out how to debug.  See the following code:</p>
  
  <pre><code>extern "C" void run_graph_(char* path){
  
  tensorflow::Status s;
  tensorflow::GraphDef gdef;
  s = tensorflow::ReadBinaryProto(tensorflow::Env::Default(), path, &amp;gdef);
  if (!s.ok()) 
  {
      std::cout &lt;&lt; "error: " &lt;&lt; s.ToString() &lt;&lt; "\n";     
  }
  else
  {
      std::cout &lt;&lt; "complete: " &lt;&lt; s.ToString() &lt;&lt; "\n"; 
  }
  
  for (int i = 0; i &lt; gdef.node_size(); i++)
  {
      if (gdef.node(i).name() == "nn_output" || gdef.node(i).name() == "nn_input")
          {
              gdef.node(i).PrintDebugString();
          }
      }
  
  tensorflow::Session* session;
  s = tensorflow::NewSession(tensorflow::SessionOptions(), &amp;session);
  s = session-&gt;Create(gdef);
  
  std::vector&lt;tensorflow::Tensor&gt; outputs;
  tensorflow::Input::Initializer a({{8.81474371e-01,   8.90273631e-01,   1.72516504e-01, 5.55829580e-04,   9.59886648e-01,   1.20462446e-02, 1.98175483e-03,   1.38663768e-02}});
  std::cout &lt;&lt; a.tensor.DebugString() &lt;&lt; std::endl;
  
  std::cout &lt;&lt; "run" &lt;&lt; std::endl;
  s = session-&gt;Run({{"nn_input", a.tensor}}, {"nn_output"}, {}, &amp;outputs);
  std::cout &lt;&lt; "ran" &lt;&lt; std::endl;
  if (!s.ok()) 
  {
      std::cout &lt;&lt; "error: " &lt;&lt; s.ToString() &lt;&lt; "\n";     
  }
  if( outputs.size() &gt; 0 )
  {
      std::cout &lt;&lt; "output: " &lt;&lt; outputs[0].DebugString() &lt;&lt; std::endl; // Tensor&lt;type: float shape: [] values: 30&gt;
  }
  
  // Free any resources used by the session
  session-&gt;Close();
  }
  </code></pre>
  
  <p>If we run this code, it works fine and we get the following output:</p>
  
  <pre><code>complete: OK
  name: "nn_input"
  op: "Placeholder"
  attr {
    key: "dtype"
    value {
      type: DT_DOUBLE
    }
  }
  attr {
    key: "shape"
    value {
      shape {
        dim {
          size: -1
        }
        dim {
          size: 8
        }
      }
    }
  }
  name: "nn_output"
  op: "Add"
  input: "MatMul_4"
  input: "Variable_4/read"
  attr {
    key: "T"
    value {
      type: DT_DOUBLE
    }
  }
  Tensor&lt;type: double shape: [1,8] values: [0.881474371 0.890273631 0.172516504]...&gt;
  run
  ran
  output: Tensor&lt;type: double shape: [1,2] values: [0.016238948144062765 0.18446201154785777]&gt;
  </code></pre>
  
  <p>However if we change the input tensor to have more than 1 row, for example:</p>
  
  <pre><code>tensorflow::Input::Initializer a({{8.81474371e-01,   8.90273631e-01,   1.72516504e-01, 5.55829580e-04,   9.59886648e-01,   1.20462446e-02, 1.98175483e-03,   1.38663768e-02}, {5.58892306e-01,   8.76436973e-01,   1.78063232e-01, 1.27910966e-01,   2.23700877e-01,   1.81518624e-01, 2.75920096e-01,   1.19812048e-02}, {3.69272573e-01,   6.75944584e-01,   8.35322158e-01, 3.89913301e-02,   4.26433973e-01,   2.94287142e-01, 1.08364415e-01,   3.93754220e-02}, {4.27477538e-01,   6.70533752e-01,   4.24946841e-02, 4.63300582e-02,   1.07105860e-02,   1.92844420e-02, 2.40294042e-02,   2.53449079e-03}, {2.66025541e-01,   9.75372575e-01,   6.53711732e-02, 7.52453239e-02,   2.75028037e-02,   1.23259054e-01, 1.29876045e-01,   1.75538941e-01}});
  </code></pre>
  
  <p>we get a seg fault when it tried to run the graph with the following output:</p>
  
  <pre><code>complete: OK
  name: "nn_input"
  op: "Placeholder"
  attr {
    key: "dtype"
    value {
      type: DT_DOUBLE
    }
  }
  attr {
    key: "shape"
    value {
      shape {
        dim {
          size: -1
        }
        dim {
          size: 8
        }
      }
    }
  }
  name: "nn_output"
  op: "Add"
  input: "MatMul_4"
  input: "Variable_4/read"
  attr {
    key: "T"
    value {
      type: DT_DOUBLE
    }
  }
  Tensor&lt;type: double shape: [5,8] values: [0.881474371 0.890273631 0.172516504]...&gt;
  run
  
  Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
  
  Backtrace for this error:
  #0  0x7fcd55f2f26f in ???
  #1  0x7fcd5488b77a in ???
  #2  0x7fcd548bebb3 in ???
  #3  0x7fcd549032c3 in ???
  #4  0x7fcd549204ef in ???
  #5  0x7fcd52beccfc in ???
  #6  0x7fcd52bbbcda in ???
  #7  0x7fcd52bad633 in ???
  #8  0x7fcd52818fc0 in ???
  #9  0x7fcd52816d09 in ???
  #10  0x7fcd5206706e in execute_native_thread_routine
          at ../../../.././libstdc++-v3/src/c++11/thread.cc:83
  #11  0x7fcd56d46e24 in ???
  #12  0x7fcd55ff234c in ???
  #13  0xffffffffffffffff in ???
  Segmentation fault
  </code></pre>
  
  <p>We are using the C++ on CentOS 7.  I believe we should be able to run a multidimensional tensor through this graph as it works in python.  Any help is appreciated.</p>