1、参考文章
①https://zhuanlan.zhihu.com/p/58964140
②https://blog.youkuaiyun.com/zugexiaodui/article/details/77130862?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
③https://blog.youkuaiyun.com/ebzxw/article/details/81591437
④https://www.cnblogs.com/codehome/p/9718611.html
2、难点:损失函数在代码中的体现
步骤:①先下载Mnist数据集
②运行第一个py文件:change.py
③运行第二个py文件:test.py,得到识别准确率
2、Mnist数据集下载地址:
下载后得到的内容:
3、编译器:Pycharm
4、第一个py文件:change.py
目的:将Mnist数据集文件转换为.csv文件
def convert(imgf, labelf, outf, n):
f = open(imgf, "rb")
o = open(outf, "w")
l = open(labelf, "rb")
f.read(16)
l.read(8)
images = []
for i in range(n):
image = [ord(l.read(1))]
for j in range(28 * 28):
image.append(ord(f.read(1)))
images.append(image)
for image in images:
o.write(",".join(str(pix) for pix in image) + "\n")
f.close()
o.close()
l.close()
convert("/Users/Downloads/MNIST_dataset/train-images.idx3-ubyte", "/UsersDownloads/MNIST_dataset/train-labels.idx1-ubyte",
"mnist_train.csv", 60000)
convert("/Users/Downloads/MNIST_dataset/t10k-images.idx3-ubyte", "/Users/Downloads/MNIST_dataset/t10k-labels.idx1-ubyte",
"mnist_test.csv", 10000)
print("Convert Finished!")
5、第二个py文件:test.py
# Code for a 3-layer neural network, and code for learning the MNIST dataset
# Zhouxw@