资源简介
使用74行python代码实现简单的手写数字识别神经网络。
输出值为10000个测试样本中识别正确的图像数量。
代码片段和文件信息
“““
mnist_loader
~~~~~~~~~~~~
A library to load the MNIST image data. For details of the data
structures that are returned see the doc strings for ‘‘load_data‘‘
and ‘‘load_data_wrapper‘‘. In practice ‘‘load_data_wrapper‘‘ is the
function usually called by our neural network code.
“““
#### Libraries
# Standard library
import cPickle
import gzip
# Third-party libraries
import numpy as np
def load_data():
“““Return the MNIST data as a tuple containing the training data
the validation data and the test data.
The ‘‘training_data‘‘ is returned as a tuple with two entries.
The first entry contains the actual training images. This is a
numpy ndarray with 50000 entries. Each entry is in turn a
numpy ndarray with 784 values representing the 28 * 28 = 784
pixels in a single MNIST image.
The second entry in the ‘‘training_data‘‘ tuple is a numpy ndarray
containing 50000 entries. Those entries are just the digit
values (0...9) for the corresponding images contained in the first
entry of the tuple.
The ‘‘validation_data‘‘ and ‘‘test_data‘‘ are similar except
each contains only 10000 images.
This is a nice data format but for use in neural networks it‘s
helpful to modify the format of the ‘‘training_data‘‘ a little.
That‘s done in the wrapper function ‘‘load_data_wrapper()‘‘ see
below.
“““
f = gzip.open(‘data/mnist.pkl.gz‘ ‘rb‘)
training_data validation_data test_data = cPickle.load(f)
f.close()
return (training_data validation_data test_data)
def load_data_wrapper():
“““Return a tuple containing ‘‘(training_data validation_data
test_data)‘‘. based on ‘‘load_data‘‘ but the format is more
convenient for use in our implementation of neural networks.
In particular ‘‘training_data‘‘ is a list containing 50000
2-tuples ‘‘(x y)‘‘. ‘‘x‘‘ is a 784-dimensional numpy.ndarray
containing the input image. ‘‘y‘‘ is a 10-dimensional
numpy.ndarray representing the unit vector corresponding to the
correct digit for ‘‘x‘‘.
‘‘validation_data‘‘ and ‘‘test_data‘‘ are lists containing 10000
2-tuples ‘‘(x y)‘‘. In each case ‘‘x‘‘ is a 784-dimensional
numpy.ndarry containing the input image and ‘‘y‘‘ is the
corresponding classification i.e. the digit values (integers)
corresponding to ‘‘x‘‘.
Obviously this means we‘re using slightly different formats for
the training data and the validation / test data. These formats
turn out to be the most convenient for use in our neural network
code.“““
tr_d va_d te_d = load_data()
training_inputs = [np.reshape(x (784 1)) for x in tr_d[0]]
training_results = [vectorized_result(y) for y in tr_d[1]]
training_data = zip(training_inputs training_results)
validation_inputs = [np.reshape(x (784 1)) for x in va_d[0]]
validation_data = zip(validation_
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 17051982 2016-11-12 12:49 data\mnist.pkl.gz
文件 3480 2017-08-18 15:09 mnist_loader.py
文件 6449 2017-08-18 15:36 network.py
文件 199 2017-08-18 16:26 recognize.py
目录 0 2017-08-18 15:09 data\
相关资源
- Python Machine Learning( Python机器学习.
- Python高效开发实战——Django、Tornado、
- eclipse中的python插件
- Python编程:从入门到实践 超清pdf 非
- Python3核心编程(第3版)中文文字版
- python机器学习经典修正python3.x版
- python 自然语言处理实战代码部分
- Python测试驱动开发(第二版)中英文
- python编写超级玛丽
- Practical Social Network Analysis with Python
- 《Python编程:从入门到实践》带源代
- Python科学计算第2版
- Computer Simulation Foundational Approach Pyt
- FlaskWeb开发:基于Python的Web应用开发实
- 用Python写网络爬虫PDF&源码
- Introduction to Python Programming and Develop
- Python网络数据采集.pdf
- Python核心编程第3版中文版.pdf
- Python编程:从入门到实践.pdf
- python学习导图
- 微信公众号开发教程1python
- Python程序设计第3版完整文字版带书签
- Python网络数据采集 高清完整.pdf版
- Python与Tkinter编程
- Introduction to Machine Learning with Python 英
- Fluent Python 无水印pdf
- Effective Python 无水印pdf
- Automate the Boring Stuff with Python 无水印
- python环境离线快速安装带pip
- 图灵书籍(流畅的Python.pdf+Python基础教
评论
共有 条评论