|
Tensorflow读取mnist图像数据并保存图像
百度网盘链接:
链接:http://pan.baidu.com/s/1i4BbOlJ
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1
- import tensorflow as tf
- import os
- from PIL import Image
- cur_dir = os.getcwd()
- print("For Tensorflow to load images")
- print("current directory:",cur_dir)
- def read_image(filename_queue):
- reader = tf.WholeFileReader()
- key,value = reader.read(filename_queue)
- image = tf.image.decode_png(value)
- return key,image
- def inputs():
- # 手写数字--灰度图像
- #filenames = ['./Test/test/1.png', './Test/test/2.png' ]
-
- FullImageList = [];
- filenames = os.listdir('./Test/test/')
- for fn in filenames:
- FullImage = os.path.join( cur_dir, 'Test/test', fn )
- FullImageList.append(FullImage)
- filename_queue = tf.train.string_input_producer(FullImageList)
- filename,read_input = read_image(filename_queue)
- return filename,read_input
- with tf.Graph().as_default():
- image = inputs()
- init = tf.global_variables_initializer()
- sess = tf.Session()
- sess.run(init)
- tf.train.start_queue_runners(sess=sess)
- for i in range(3):
- filename,img = sess.run(image)
- print (filename)
- # 手写数字--灰度图像
- img = Image.fromarray(img[:,:,0], "L")
- img.save(os.path.join(cur_dir+'/Test/',"ysw"+str(i)+".bmp"))
-
复制代码
|
|