(filename, tfrecord_writer, offset=0)
return offset + num_images
Loads data from the cifar10 pickle files and writes files to a TFRecord.

  Args:
    filename: The filename of the cifar10 pickle file.
    tfrecord_writer: The TFRecord writer to use for writing.
    offset: An offset into the absolute number of images previously written.

  Returns:
    The new offset.
Loads data from the cifar10 pickle files and writes files to a TFRecord.
Loads data from the cifar10 pickle files and writes files to a TFRecord .
def _add_to_tfrecord(filename, tfrecord_writer, offset=0):
  """Loads data from the cifar10 pickle files and writes files to a TFRecord.

  Args:
    filename: The filename of the cifar10 pickle file.
    tfrecord_writer: The TFRecord writer to use for writing.
    offset: An offset into the absolute number of images previously written.

  Returns:
    The new offset.
  """
  with tf.gfile.Open(filename, 'r') as f:
    data = cPickle.load(f)

  images = data['data']
  num_images = images.shape[0]

  images = images.reshape((num_images, 3, 32, 32))
  labels = data['labels']

  with tf.Graph().as_default():
    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/%d' % (
            filename, offset + j + 1, offset + num_images))
        sys.stdout.flush()

        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)
        tfrecord_writer.write(example.SerializeToString())

  return offset + num_images
def _add_to_tfrecord ( filename , tfrecord_writer , offset = 0 ) : with tf . gfile . Open ( filename , 'r' ) as f : data = cPickle . load ( f ) images = data [ 'data' ] num_images = images . shape [ 0 ] images = images . reshape ( ( num_images , 3 , 32 , 32 ) ) labels = data [ 'labels' ] with tf . Graph ( ) . as_default ( ) : 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/%d' % ( filename , offset + j + 1 , offset + num_images ) ) sys . stdout . flush ( ) 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 ) tfrecord_writer . write ( example . SerializeToString ( ) ) return offset + num_images