深度学习笔记-第3章-《深度学习入门——基于Python的理论与实现》的代码解说

这个书各位大佬都很熟悉,我就不多说了。这个系列的文章肯定不是很长,整个整合到
机器学习-笔记目录

方便的Numpy查询手册
https://docs.scipy.org/doc/numpy/search.html

版面尽量干净,分成三部分,代码图,重要的语法,举例扩展。

1.代码图

  • show_mnist.py
    这个文件是结果展示文件,我把我的标号的备注都去除掉了。
    在这里插入图片描述

  • 1.1 neuralnet_mnist.py

这个文件用于读取simple_weight.pkl来获得已经计算好的权重,代入计算用10000张图片来测试,计算精确度。
这个图因为比较小,备注也少,是完整的

在这里插入图片描述

.
.

2.涉及的语法

这里我截取主要的部分,最后总结一下。

This module provides a simple interface to compress and decompress files just like the GNU programs gzip and gunzip would.
The data compression is provided by the zlib module.

gzip.open(filename, mode='rb', compresslevel=9, encoding=None, errors=None, newline=None)

Open a gzip-compressed file in binary or text mode, returning a file object.
The filename argument can be an actual filename (a str or bytes object), or an existing file object to read from or write to.
The mode argument can be any of ‘r’, ‘rb’, ‘a’, ‘ab’, ‘w’, ‘wb’, ‘x’ or ‘xb’ for binary mode, or ‘rt’, ‘at’, ‘wt’, or ‘xt’ for text mode. The default is ‘rb’.
The compresslevel argument is an integer from 0 to 9, as for the GzipFile constructor.
For binary mode, this function is equivalent to the GzipFile constructor: GzipFile(filename, mode, compresslevel). In this >case, the encoding, errors and newline arguments must not be provided.

这个主要是用来解压几个.gz文件的,默认以二进制打开,代码中是gzip.open(file_path, 'rb')打开了四个.gz文件
需要注意的是,gzip打开文件,也可以接受文件对象。并且打开了文件之后返回的也是文件对象,不过我更喜欢说是文件操作符。举例在最后面
下一步的处理是data = np.frombuffer(f.read(), np.uint8, offset=16)放在下面讲

详细见上文的原文部分。以下是它的一些其它功能

gzip.compress(data, compresslevel=9)

Compress the data, returning a bytes object containing the compressed data. compresslevel has the same meaning as in the GzipFile constructor above.

gzip.decompress(data)

Decompress the data, returning a bytes object containing the uncompressed data.

gzip的源代码:https://github.com/python/cpython/blob/3.6/Lib/gzip.py

  • 2.np.frombuffer

https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.frombuffer.html

Interpret a buffer as a 1-dimensional array.

numpy.frombuffer(buffer, dtype=float, count=-1, offset=0)
在这里插入图片描述
这里牵扯很多,另外一篇写这个的。
https://blog.csdn.net/qq_42731466/article/details/83480156

基本文档
https://docs.scipy.org/doc/numpy-1.13.0/user/basics.types.html
更高级的
https://docs.scipy.org/doc/numpy-1.13.0/user/basics.rec.html#structured-arrays

.
.

3.pickle
https://docs.python.org/3.6/library/pickle.html
有空再展开。

.
.
.
.
.

3. 举例

小例子做扩展,可完全跳过。

结尾
在我的图上,加了很多代码的注释,作为图层分开放了,为了看起来简洁明了我将图层隐去了。不隐藏的时候,代码图是这样的,需要的请自行下载dwg,不下载也不影响,该说的都说完了。

红色是变量监控,橘色是注释,紫色是详细注释和超链接,ctrl一下就能飞过去。
这是我能截取的最大的范围了,缩小字会看不清,所以上面的图我把注释去掉了。
在这里插入图片描述
下载链接
https://download.csdn.net/download/qq_42731466/10748151

更新时间
2018.10.28——更新show_mnist的代码图和几处重要的语法。

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值