Image 枕头:如何显示MNIST数据?

Image 枕头:如何显示MNIST数据?,image,pillow,mnist,Image,Pillow,Mnist,我已经创建了一个(LeNet-5),它提供了相当好的准确性(98%) 然后我试着看看它在我手写数据上的表现(显然是来自不同的发行版,只是好奇而已)。因此,我拍摄了一张5的照片,并使用PIL将其转换为灰度,然后观察它的预测结果。它的表现并不好 要转换为灰度的代码: # Open the file im = Image.open(path) # Resize the image im_resized = im.resize(size) # Convert to grayscale gr = Im

我已经创建了一个(LeNet-5),它提供了相当好的准确性(98%)

然后我试着看看它在我手写数据上的表现(显然是来自不同的发行版,只是好奇而已)。因此,我拍摄了一张
5
的照片,并使用
PIL
将其转换为灰度,然后观察它的预测结果。它的表现并不好

要转换为灰度的代码:

# Open the file
im = Image.open(path)

# Resize the image
im_resized = im.resize(size)

# Convert to grayscale
gr = ImageOps.grayscale(im_resized)
而且它在互联网上的其他一些图片上也表现不好。然后我从数字上开始怀疑

MNIST:背景为黑色,数字为白色

我的图像:背景是白色,数字是黑色

所以我想看看MNIST的照片。但我得到的只是一些白点。没有任何有意义的图像

以下是查看图像的代码片段:

from mnist import MNIST
mndata = MNIST(mndir)

train_images, train_labels = mndata.load_training()
test_images, test_labels = mndata.load_testing()

ar = np.array(test_images[10], np.int32)
ar = np.resize(ar, (28, 28))
im = Image.fromarray(ar, 'L')
im.show()
为此,我得到如下结果:


以下是查看图像的小代码。这有助于打印MNIST的内联图像

get_ipython().magic(u'matplotlib inline') #to print inline images

import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt

#load the data

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', validation_size=0)

#we can plot an example image from the MNIST dataset.
img = mnist.train.images[2]
plt.imshow(img.reshape((28, 28)), cmap='Greys_r')
理想情况下,这应该是可行的