Tensorflow 从mnist数据集中读取一幅图像并保存

import tensorflow as tf

from tensorflow.examples.tutorials.mnist import input_data

from PIL import Image, ImageFilter
import numpy as np
import matplotlib.pyplot as plt
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
tf.reset_default_graph()

# #################################################
im=mnist.test.images[1].reshape((28,28))     #读取的格式为Ndarry
img= Image.fromarray(im*255)                 #Image和Ndarray互相转换
img= img.convert('RGB')                           #jpg可以是RGB模式,也可以是CMYK模式
img.save(r'G:\Exercise\Python\02.jpg')       #保存
plt.imshow(im,cmap="gray")  
plt.show()                                                   #显示
# ###################################################

猜你喜欢

转载自blog.csdn.net/qq_23981335/article/details/80014281