import tensorflow as tf

      image_placeholder = tf.placeholder(dtype=tf.uint8)
      encoded_image = tf.image.encode_png(image_placeholder)

      with tf.Session('') as sess:

        for j in range(num_images):
          sys.stdout.write('\r>> Reading file [%s] image %d' % (
              filename, offset + 1))
          sys.stdout.flush()

          if ('train' == name) and ( math.floor(offset / images_per_shard) > shard) :
            tfrecord_writer.close()
            shard = shard + 1
            record_filename = _get_output_filename(dataset_dir, name, shard, FLAGS.train_shards)
            tfrecord_writer = tf.python_io.TFRecordWriter(record_filename)

          image = np.squeeze(images[j]).transpose((1, 2, 0))
          label = labels[j]

          png_string = sess.run(encoded_image,
                                feed_dict={image_placeholder: image})

          example = dataset_utils.image_to_tfexample(
              png_string, 'png', _IMAGE_SIZE, _IMAGE_SIZE, label, _CLASS_NAMES[label])
          tfrecord_writer.write(example.SerializeToString())
          offset = offset + 1

  tfrecord_writer.close()
