title: Importing jpeg files returns black image in TensorFlow?
body: <p>I created a convolutional network that classifies images. All the images were of a jpeg file format, but I had to create a function that would process the images before feeding it into my network.</p>
  
  <p>This is the import functioned I defined:</p>
  
  <pre><code>import tensorflow as tf
  
  def import_image(image_location):
      image_contents = tf.read_file(image_location)
      decoded_image = tf.image.decode_jpeg(contents=image_contents, channels=3)
      cropped_image = tf.image.resize_image_with_crop_or_pad(decoded_image, 100, 100)
  
      return cropped_image
  </code></pre>
  
  <p>After running the program for 22 iterations, I saw that the classification accuracy was terrible. I, at first, attributed its failure to the number of iterations I had tasked to it. I soon added TensorBoard functionality and with the function <code>tf.summary.image("Cropped Image", cropped_image)</code>, I saw that the input image was completely black. I then added histograms and summary scalars displaying the cross entropy vs. iterations and this is what came out:<a href="https://i.stack.imgur.com/Y4qRQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y4qRQ.jpg" alt="Histogram"></a><a href="https://i.stack.imgur.com/BqWlY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BqWlY.jpg" alt="Cross Entropy"></a></p>
  
  <p>After seeing that the input image is completely black, the results make sense. The network is not being trained at all. So, what's wrong with the import function? Or have I not used <code>tf.summary.image()</code> appropriately? Any help is appreciated. Thanks.</p>