深度学习实战 fashion-mnist数据集预处理技术分析

栏目: 编程工具 · 发布时间: 6年前

内容简介:本文首发于微信公众号:"算法与编程之美",欢迎关注,及时了解更多此系列文章。keras的fashion-mnist数据集的源码为:

欢迎点击「算法与编程之美」↑关注我们!

本文首发于微信公众号:"算法与编程之美",欢迎关注,及时了解更多此系列文章。

keras的fashion-mnist数据集的源码为:

def load_data():

"""Loads the Fashion-MNIST dataset.

# Returns

Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`.

"""

dirname = os.path.join('datasets', 'fashion-mnist')

base = 'http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/'

files = ['train-labels-idx1-ubyte.gz', 'train-images-idx3-ubyte.gz',

't10k-labels-idx1-ubyte.gz', 't10k-images-idx3-ubyte.gz']

paths = []

for fname in files:

paths.append(get_file(fname,

origin=base + fname,

cache_subdir=dirname))

with gzip.open(paths[0], 'rb') as lbpath:

y_train = np.frombuffer(lbpath.read(), np.uint8, offset=8)

with gzip.open(paths[1], 'rb') as imgpath:

x_train = np.frombuffer(imgpath.read(), np.uint8,

offset=16).reshape(len(y_train), 28, 28)

with gzip.open(paths[2], 'rb') as lbpath:

y_test = np.frombuffer(lbpath.read(), np.uint8, offset=8)

with gzip.open(paths[3], 'rb') as imgpath:

x_test = np.frombuffer(imgpath.read(), np.uint8,

offset=16).reshape(len(y_test), 28, 28)

return (x_train, y_train), (x_test, y_test)

fashion-mnist数据集以四个gzip格式的方式存储在远程服务器上,利用keras的get_file()下载到本地的keras缓存目录。

然后利用gzip的open()打开文件,利用numpy的frombuffer方法直接加载numpy的数组。如果是图像数据的话,需要进行reshape操作。

此处,为什么加载图片数据的时候需要offset=16,标签数据的时候需要offset=8?

fashion-mnist图像数据集的预处理方式和mnist有很大的不同,四个gz文件分别存放了x_train, y_train, x_test, y_test四个部分,然后分别读取四个文件利用np.frombuffer()方式加载。这种处理方式相对mnist来说复杂一些。 为什么会这样处理?

欢迎持续关注。

where2 go 团队

   

微信号:算法与编程之美          

深度学习实战 fashion-mnist数据集预处理技术分析

长按识别二维码关注我们!

温馨提示: 点击页面右下角 “写留言”发表评论,期待您的参与!期待您的转发!


以上所述就是小编给大家介绍的《深度学习实战 fashion-mnist数据集预处理技术分析》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Design Accessible Web Sites

Design Accessible Web Sites

Jeremy Sydik / Pragmatic Bookshelf / 2007-11-05 / USD 34.95

It's not a one-browser web anymore. You need to reach audiences that use cell phones, PDAs, game consoles, or other "alternative" browsers, as well as users with disabilities. Legal requirements for a......一起来看看 《Design Accessible Web Sites》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具