关于解决上面深度学习入门中根据源代码下载到mnist数据集,训练识别率超级低问题

深度学习入门中,里面调用的代码是老师自己对一个读入训练数据和测试数据的函数的改写,

我在调用该函数的过程中,发生了识别率超级低的问题,详情请看上一篇博客,在今天看书的过程中看到mnist_show.py调用的函数其实可以用系统本身读入训练数据和测试数据的函数,于是问题就解决了。

下面附上我这次修改后的代码结果与原来代码结果的比较。

 

上图是我调用系统封装函数的生成结果

上图是我采用深度学习入门中load_mnist()函数生成的结果,二者对比是非常明显了。

最后附上我这次修改的代码,因为改动比较大。

mnist_show.py

# coding: utf-8
import sys, os
import cv2
sys.path.append(os.pardir)  # 为了导入父目录的文件而进行的设定
import numpy as np
from dataest.mnist import load_mnist
from PIL import Image
import struct
import shutil
from keras.datasets import mnist


def img_show(img):
    pil_img = Image.fromarray(np.uint8(img))
    pil_img.show()

def setDir():
    if  not os.path.exists('./test'):
        os.makedirs('./test')
    else:
        shutil.rmtree('./test')
        os.mkdir('./test')



#调用系统封装的读入训练数据和测试数据的函数
#(x_train, t_train), (x_test, t_test) = mnist.load_data()
#调用深度学习入门这本书中带有的函数
(x_train, t_train), (x_test, t_test) = load_mnist(normalize=False, flatten=True)
#刚开始进行文件夹的处理。
setDir()
#处理十张手写数字体(mnist数据集带有的)
for i in range(0,10):
	img = x_train[i]
	label = t_train[i]
	img = img.reshape(28, 28)
	#Image.save('mnistpicture/'+img+'.png')
	
	fileName="./test/"+str(i)+"-"+str(t_train[i])+".bmp"
	cv2.imwrite(fileName, img)
	print(label)  # 5
	#img.show()

#print(img.shape)  # (784,)
#img = img.reshape(28, 28)  # 把图像的形状变为原来的尺寸
#print(img.shape)  # (28, 28)

#img_show(img)

 

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐