前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >深度学习实战 fashion-mnist数据集预处理技术分析

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

作者头像
算法与编程之美
发布2019-07-17 17:57:10
1.1K0
发布2019-07-17 17:57:10
举报
文章被收录于专栏:算法与编程之美

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

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

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来说复杂一些。为什么会这样处理?

欢迎持续关注。

where2go 团队


微信号:算法与编程之美

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

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-05-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 算法与编程之美 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档