Tensorflow reads an image from the mnist dataset and saves it

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))     #The read format is Ndarry
img= Image.fromarray(im*255)                 #Image and Ndarray are converted to each other
img= img.convert('RGB ')                           #jpg can be in RGB mode or CMYK mode
img.save(r'G:\Exercise\Python\02.jpg')       #Save
plt.imshow(im,cmap="gray")  
plt.show( )                                                   #display
# ############################################## #####

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324585628&siteId=291194637