我创建了一个model(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()
为此我得到了类似的东西:
答案 0 :(得分:0)
这是查看该图像的一小段代码。这有助于打印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')
这应该可行。