title: Tensorflow Facenet Classifier in C++
body: <p>I've been trying to implement the <a href="https://github.com/davidsandberg/facenet" rel="nofollow noreferrer">facenet classifier</a>, originally written in python, into C++ and for the most part it works well. I've been read images in with opencv and convert to tensorflow tensors, however after running the graph my output tensor is filled with NaN values. </p>
  
  <p>Heres the code section: </p>
  
  <pre><code>string input_layer = "input:0";
  string phase_train_layer = "phase_train:0";
  string output_layer = "embeddings:0";
  
  tensorflow::Tensor input_tensor(tensorflow::DT_FLOAT, tensorflow::TensorShape({input_Images.size(), height, width, channels}));
  auto input_tensor_mapped = input_tensor.tensor&lt;float, 4&gt;();        
  
  for (int i = 0; i &lt; input_Images.size(); i++) {
      Mat image = input_Images[i];
      const float * source_data = (float*) image.data;
      for (int h = 0; h &lt; image.rows; ++h) {
          const float* source_row = source_data + (h * image.cols * image.channels());
          for (int w = 0; w &lt; image.cols; ++w) {
              const float* source_pixel = source_row + (w * image.channels());
              for (int c = 0; c &lt; image.channels(); ++c) {
                  const float* source_value = source_pixel + c;
                  //std::cout &lt;&lt; *source_value &lt;&lt; std::endl;
                  input_tensor_mapped(i, h, w, c) = *source_value;
              }
          }
      }
  }
  
  tensorflow::Tensor phase_tensor(tensorflow::DT_BOOL, tensorflow::TensorShape());
  phase_tensor.scalar&lt;bool&gt;()() = false;
  
      cout &lt;&lt; phase_tensor.DebugString() &lt;&lt; endl;
      cout &lt;&lt; input_tensor.DebugString() &lt;&lt; endl;
  std::vector&lt;tensorflow::Tensor&gt; outputs;
  
  std::vector&lt;std::pair&lt;string, tensorflow::Tensor&gt;&gt; feed_dict = {
      {input_layer, input_tensor},  
      {phase_train_layer, phase_tensor},
  };    
  
  Status run_status = session-&gt;Run(feed_dict,
                              {output_layer}, {} , &amp;outputs);
  if (!run_status.ok()) {
      LOG(ERROR) &lt;&lt; "\tRunning model failed: " &lt;&lt; run_status &lt;&lt; "\n";
      return -1;
  }
  
  cout &lt;&lt; outputs[0].DebugString() &lt;&lt; endl;
  </code></pre>
  
  <p>Any ideas why this might be the case?</p>