(data_filename, labels_filename, num_images,
                     tfrecord_writer)
Loads data from the binary MNIST files and writes files to a TFRecord.

  Args:
    data_filename: The filename of the MNIST images.
    labels_filename: The filename of the MNIST labels.
    num_images: The number of images in the dataset.
    tfrecord_writer: The TFRecord writer to use for writing.
Loads data from the binary MNIST files and writes files to a TFRecord.
Loads data from the binary MNIST files and writes files to a TFRecord .
def _add_to_tfrecord(data_filename, labels_filename, num_images,
                     tfrecord_writer):
  """Loads data from the binary MNIST files and writes files to a TFRecord.

  Args:
    data_filename: The filename of the MNIST images.
    labels_filename: The filename of the MNIST labels.
    num_images: The number of images in the dataset.
    tfrecord_writer: The TFRecord writer to use for writing.
  """
  images = _extract_images(data_filename, num_images)
  labels = _extract_labels(labels_filename, num_images)

  shape = (_IMAGE_SIZE, _IMAGE_SIZE, _NUM_CHANNELS)
  with tf.Graph().as_default():
    image = tf.placeholder(dtype=tf.uint8, shape=shape)
    encoded_png = tf.image.encode_png(image)

    with tf.Session('') as sess:
      for j in range(num_images):
        sys.stdout.write('\r>> Converting image %d/%d' % (j + 1, num_images))
        sys.stdout.flush()

        png_string = sess.run(encoded_png, feed_dict={image: images[j]})

        example = dataset_utils.image_to_tfexample(
            png_string, 'png'.encode(), _IMAGE_SIZE, _IMAGE_SIZE, labels[j])
        tfrecord_writer.write(example.SerializeToString())
def _add_to_tfrecord ( data_filename , labels_filename , num_images , tfrecord_writer ) : images = _extract_images ( data_filename , num_images ) labels = _extract_labels ( labels_filename , num_images ) shape = ( _IMAGE_SIZE , _IMAGE_SIZE , _NUM_CHANNELS ) with tf . Graph ( ) . as_default ( ) : image = tf . placeholder ( dtype = tf . uint8 , shape = shape ) encoded_png = tf . image . encode_png ( image ) with tf . Session ( '' ) as sess : for j in range ( num_images ) : sys . stdout . write ( '\r>> Converting image %d/%d' % ( j + 1 , num_images ) ) sys . stdout . flush ( ) png_string = sess . run ( encoded_png , feed_dict = { image : images [ j ] } ) example = dataset_utils . image_to_tfexample ( png_string , 'png' . encode ( ) , _IMAGE_SIZE , _IMAGE_SIZE , labels [ j ] ) tfrecord_writer . write ( example . SerializeToString ( ) )