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)

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 )
loads data from the binary mnist files and writes files to a tfrecord .