title: Use tf.data.Dataset for ppm files
body: <p>I would like to use <code>tf.data.DataSet</code> with ppm images, but this is not supported out of the box and I am stuck trying to find a possible workaround.</p>
  
  <p>I created a list of images <code>image_names</code> that stores the names of all files I'd like to import in the dataset. Following the TensorFlow tutorial, I wrote the following code (for jpeg images):</p>
  
  <pre class="lang-py prettyprint-override"><code>def parse_function1(filename):
      image_string = tf.read_file(filename)
      image = tf.image.decode_jpeg(image_string, channels=3)
  
      image = tf.image.convert_image_dtype(image, tf.float32)
  
      return image
  
  # Create a dataset, iterator and print some data
  dataset = tf.data.Dataset.from_tensor_slices(image_names)
  dataset = dataset.shuffle(len(image_names))
  dataset = dataset.map(parse_function1, num_parallel_calls=1)
  
  iterator = dataset.make_initializable_iterator()
  next_element = iterator.get_next()
  init_op = iterator.initializer
  
  with tf.Session() as sess:
      # Initialize the iterator
      sess.run(init_op)
      print(sess.run(next_element))
  </code></pre>
  
  <p>This unfortunately does not work with ppm files (there's no <code>tf.image.decode_ppm</code>), so I tried to create an alternative parse function that uses imageio to read files from disk:</p>
  
  <pre class="lang-py prettyprint-override"><code>def parse_function2(filename):
      img_raw = imageio.imread(filename)
      img_tensor = tf.convert_to_tensor(img_raw, dtype=tf.float32)
      return img_tensor
  </code></pre>
  
  <p>Running the script with <code>parse_function2</code> throws an error:</p>
  
  <pre><code>File ".local/lib/python3.7/site-packages/imageio/core/request.py", line 240, in _parse_uri
      raise IOError("Cannot understand given URI: %s." % uri_r)
  OSError: Cannot understand given URI: &lt;tf.Tensor 'args_0:0' shape=() dtype=string&gt;.
  </code></pre>
  
  <p>My understanding is that the argument <code>filename</code> is actually a tensor holding a string value, so I tried to construct the dataset using a <code>py_function</code> wrapper. Instead of calling</p>
  
  <pre class="lang-py prettyprint-override"><code>dataset = dataset.map(parse_function2, num_parallel_calls=1)
  </code></pre>
  
  <p>I do</p>
  
  <pre class="lang-py prettyprint-override"><code>dataset = dataset.map(lambda x : tf.py_function(parse_function2, [x], Tout=[tf.float32]), num_parallel_calls=1)
  </code></pre>
  
  <p>Now I'm getting an imageio error saying</p>
  
  <pre><code>File "/home/martin/.local/lib/python3.7/site-packages/imageio/core/request.py", line 240, in _parse_uri
      raise IOError("Cannot understand given URI: %s." % uri_r)
  
  OSError: Cannot understand given URI: &lt;tf.Tensor: id=21, shape=(), dtype=string, numpy=b'/home/....
  </code></pre>
  
  <p>Could you please suggest how to solve this. Would you recommend not using <code>tf.data.Dataset</code> at all and writing my own class instead? I'm afraid this would never be as efficient as the original <code>Dataset</code> class.</p>