title: how to convert images in a directory to TFRecords
body: <p>I have a directory that consisted of captcha images, each image has the same name with the number on captcha. The maximum length of the captchas is 5. And I wanted to convert these images into TFRecords. To do so, I am using following functions;</p>
  
  <pre><code>def decode_label(label):
      one_hot_label = np.zeros([5, 10])
      index = [[0, 1, 2, 3, 4], map(int, list(label))]
      one_hot_label[index] = 1.0
      return one_hot_label.astype(np.uint8)
  
  
  
  def bytes_feature(value):
      return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
  
  
  
  def convert_to(dir, name, path):
      filenames = map(lambda filename: os.path.join(dir, filename), os.listdir(dir))
      tfrecords_name = os.path.join(path, name + ".tfrecords")
      writer = tf.python_io.TFRecordWriter(tfrecords_name)
      for filename in filenames:
          image = imread(filename)
          label = decode_label(re.findall("_(.*?)\.", filename)[0])
          example = tf.train.Example(features=tf.train.Features(feature={'label': bytes_feature(label.tostring()),
                                                                         'image': bytes_feature(image.tostring())}))
          writer.write(example.SerializeToString())
      writer.close()
      print("successfully convert data to tfrecords!")
  </code></pre>
  
  <p>However, I am getting the following error because of the line</p>
  
  <pre><code>label = decode_label(re.findall("_(.*?)\.", filename)[0])
  </code></pre>
  
  <blockquote>
    <p>IndexError: list index out of range</p>
  </blockquote>