我已经创建了一个模型 (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的照片。但我只得到了一些白点。根本没有任何意义的图像。
下面是查看图像的代码片段:
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()为此,我得到了如下内容:

发布于 2018-10-23 10:46:12
下面是一个查看图像的小代码。这有助于打印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')理想情况下,这应该是可行的。
https://stackoverflow.com/questions/50079361
复制相似问题