TF:利用TF读取数据操作,将CIFAR-10 数据集中的训练图片读取出来,并保存为.jpg格式

TF:利用TF读取数据操作,将CIFAR-10 数据集中的训练图片读取出来,并保存为.jpg 格式


输出结果

核心代码

def inputs_origin(data_dir):
  filenames = [os.path.join(data_dir, 'data_batch_%d.bin' % i)
               for i in range(1, 6)]
……

  filename_queue = tf.train.string_input_producer(filenames)

  read_input = cifar10_input.read_cifar10(filename_queue)
  reshaped_image = tf.cast(read_input.uint8image, tf.float32) 

  return reshaped_image  

if __name__ == '__main__':

  with tf.Session() as sess:
    reshaped_image = inputs_origin('cifar10_data/cifar-10-batches-bin')

    threads = tf.train.start_queue_runners(sess=sess) 

    sess.run(tf.global_variables_initializer())

    if not os.path.exists('cifar10_data/raw/'):
      os.makedirs('cifar10_data/raw/')

    for i in range(30):
      image_array = sess.run(reshaped_image)
      scipy.misc.toimage(image_array).save('cifar10_data/raw/%d.jpg' % i) 

(0)

相关推荐