Tensorflow的官方MNIST模型具有较高的训练精度,但预测性能较低

问题描述 投票:0回答:2

我是机器学习的新手,我跟随Tensorflow官方MNIST模型(https://github.com/tensorflow/models/tree/master/official/mnist)。在训练了3个时期的模型并获得超过98%的准确度结果之后,我决定用我自己的一些手写图像测试数据集,这些图像非常接近于MNIST数据集中的图像:

    {'loss': 0.03686057, 'global_step': 2400, 'accuracy': 0.98729998}

手写1,预测为2:https://storage.googleapis.com/imageexamples/example1.png

手写4,预测为5:https://storage.googleapis.com/imageexamples/example4.png

手写7,正确预测为7:https://storage.googleapis.com/imageexamples/example7.png

但是,正如您在下面看到的,预测大多是不正确的。任何人都可以分享一些有关这可能是什么的见解吗?如果您需要任何其他信息,请告诉我们。谢谢!

[2 5 7]
Result for output key probabilities:
[[  1.47042423e-01   1.40417784e-01   2.80471593e-01   1.18162427e-02
    1.71029475e-02   1.15245730e-01   9.41787264e-04   1.71402004e-02
    2.61987478e-01   7.83374347e-03]
 [  3.70134876e-05   3.59491096e-03   1.70885725e-03   3.44008535e-01
    1.75098982e-02   6.24581575e-01   1.02930271e-05   3.97418407e-05
    7.59732258e-03   9.11886105e-04]
 [  7.62941269e-03   7.74145573e-02   1.42017215e-01   4.73754480e-03
    3.75231934e-06   7.16139004e-03   4.40478354e-04   7.60131121e-01
    4.09408152e-04   5.51677040e-05]]

这是我用来将png转换为npy数组进行测试的脚本。提供的'3'和'5'图像的结果数组与TF存储库中给出的数组相同,所以我不认为这是问题所在:

def main(unused_argv):

output = []
images = []

filename_generate = True
index = 0

if FLAGS.images is not None:
    images = str.split(FLAGS.images)
if FLAGS.output is not "": # check for output names and make sure outputs map to images
    output = str.split(FLAGS.output)
    filename_generate = False
    if len(output) != len(images):
        raise ValueError('The number of image files and output files must be the same.')

if FLAGS.batch == "True":
    combined_arr = np.array([]) # we'll be adding up arrays

for image_name in images:
    input_image = Image.open(image_name).convert('L') # convert to grayscale
    input_image = input_image.resize((28, 28)) # resize the image, if needed
    width, height = input_image.size
    data_image = array('B')
    pixel = input_image.load()
    for x in range(0,width):
        for y in range(0,height):
            data_image.append(pixel[y,x]) # use the MNIST format
    np_image = np.array(data_image)
    img_arr = np.reshape(np_image, (1, 28, 28))
    img_arr = img_arr/float(255) # use scale of [0, 1]
    if FLAGS.batch != "True":
        if filename_generate:
            np.save("image"+str(index), img_arr) # save each image with random filenames
        else:
            np.save(output[index], img_arr) # save each image with chosen filenames
        index = index+1
    else:
        if combined_arr.size == 0:
            combined_arr = img_arr
        else:
            combined_arr = np.concatenate((combined_arr, img_arr), axis=0) # add all image arrays to one array
if FLAGS.batch == "True":
    if filename_generate:
        np.save("images"+str(index), combined_arr) # save batched images with random filename
    else:
        np.save(output[0], combined_arr) # save batched images with chosen filename 

我没有在官方的MNIST模型中改变任何东西,除了纪元的数量(之前的40个,因为它需要很长时间才能进行训练并且在1个纪元后已经看到高精度)。

非常感谢!

python tensorflow machine-learning conv-neural-network mnist
2个回答
4
投票

MNIST图像是白底黑字;您链接的图像是黑白照片。

除非我错过了转换步骤,否则您需要在尝试检测之前反转颜色。


0
投票

MNIST图像的像素值范围从0.00到1.00,从黑到白。通常当你使用自己的图像时,它将是0到255.我不确定我是否错过了将其映射回0.0-1.0的任何编码。可以尝试打印出存储像素值的数组,确保白色像素接近或等于1.0,黑色像素接近或等于0.0。

© www.soinside.com 2019 - 2024. All rights reserved.