title: How do I convert a numpy Array to a data type that tensorflow can classify?
body: <p>I am writing a Python program to detect the state of a chess board and I am using a sliding window to detect the position of each piece. My main program detects the chessboard within an image and passes its cropped picture to the my_sliding_window method. This is supposed to use Tensorflow to detect a piece in the sliding window. From <a href="https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/index.html?index=..%2F..%2Findex#0" rel="nofollow noreferrer">this</a> tutorial I saw that pictures are read like this:</p>
  
  <pre><code>image_data = tf.gfile.FastGFile('picture.jpg', 'rb').read()
  </code></pre>
  
  <p>But I don't want to read it from file as I already have the picture in a numpy array. How do make my numpy array in such a way that it can be classified by Tensorflow?</p>
  
  <p>Thank you.</p>
  
  <p>Code:</p>
  
  <pre><code>import tensorflow as tf, sys
  import cv2
  
  image_path = sys.argv[1]
  
  
  img = cv2.imread('picture.jpg')
  image_data = tf.convert_to_tensor(img)
  print type(image_data)    # this returns &lt;class 'tensorflow.python.framework.ops.Tensor'&gt;
  
  # This is what is used in the tutorial I mentioned above
  image_data2 = tf.gfile.FastGFile(image_path, 'rb').read()
  print type(image_data2)    # this returns &lt;type 'str'&gt;
  
  
  # Loads label file, strips off carriage return
  label_lines = [line.rstrip() for line
                 in tf.gfile.GFile("retrained_labels.txt")]
  
  # Unpersists graph from file
  with tf.gfile.FastGFile("retrained_graph.pb", 'rb') as f:
      graph_def = tf.GraphDef()
      graph_def.ParseFromString(f.read())
      _ = tf.import_graph_def(graph_def, name='')
  
  with tf.Session() as sess:
      # Feed the image_data as input to the graph and get first prediction
      softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
  
      predictions = sess.run(softmax_tensor, \
           {'DecodeJpeg/contents:0': image_data})
  
      # Sort to show labels of first prediction in order of confidence
      top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
  
      for node_id in top_k:
          human_string = label_lines[node_id]
          score = predictions[0][node_id]
          print('%s (score = %.5f)' % (human_string, score))
  </code></pre>