MNIST数据集比较小,一般入门机器学习都会采用这个数据集来训练
下载地址:yann.lecun.com/exdb/mnist/
有4个有用的文件:
train-images-idx3-ubyte: training set images
train-labels-idx1-ubyte: training set labels
t10k-images-idx3-ubyte: test set images
t10k-labels-idx1-ubyte: test set labels
The training set contains 60000 examples, and the test set 10000 examples. 数据集存储是用binary file存储的,黑白图片。
下面给出load数据集的代码:
import os import struct import numpy as np import matplotlib.pyplot as plt def load_mnist(): ''' Load mnist data http://yann.lecun.com/exdb/mnist/ 60000 training examples 10000 test sets Arguments: kind: 'train' or 'test', string charater input with a default value 'train' Return: xxx_images: n*m array, n is the sample count, m is the feature number which is 28*28 xxx_labels: class labels for each image, (0-9) ''' root_path = '/home/cc/deep_learning/data_sets/mnist' train_labels_path = os.path.join(root_path, 'train-labels.idx1-ubyte') train_images_path = os.path.join(root_path, 'train-images.idx3-ubyte') test_labels_path = os.path.join(root_path, 't10k-labels.idx1-ubyte') test_images_path = os.path.join(root_path, 't10k-images.idx3-ubyte') with open(train_labels_path, 'rb') as lpath: # '>' denotes bigedian # 'I' denotes unsigned char magic, n = struct.unpack('>II', lpath.read(8)) #loaded = np.fromfile(lpath, dtype = np.uint8) train_labels = np.fromfile(lpath, dtype = np.uint8).astype(np.float) with open(train_images_path, 'rb') as ipath: magic, num, rows, cols = struct.unpack('>IIII', ipath.read(16)) loaded = np.fromfile(train_images_path, dtype = np.uint8) # images start from the 16th bytes train_images = loaded[16:].reshape(len(train_labels), 784).astype(np.float) with open(test_labels_path, 'rb') as lpath: # '>' denotes bigedian # 'I' denotes unsigned char magic, n = struct.unpack('>II', lpath.read(8)) #loaded = np.fromfile(lpath, dtype = np.uint8) test_labels = np.fromfile(lpath, dtype = np.uint8).astype(np.float) with open(test_images_path, 'rb') as ipath: magic, num, rows, cols = struct.unpack('>IIII', ipath.read(16)) loaded = np.fromfile(test_images_path, dtype = np.uint8) # images start from the 16th bytes test_images = loaded[16:].reshape(len(test_labels), 784) return train_images, train_labels, test_images, test_labels
再看看图片集是什么样的:
def test_mnist_data(): ''' Just to check the data Argument: none Return: none ''' train_images, train_labels, test_images, test_labels = load_mnist() fig, ax = plt.subplots(nrows = 2, ncols = 5, sharex = True, sharey = True) ax =ax.flatten() for i in range(10): img = train_images[i][:].reshape(28, 28) ax[i].imshow(img, cmap = 'Greys', interpolation = 'nearest') print('corresponding labels = %d' %train_labels[i]) if __name__ == '__main__': test_mnist_data()
跑出的结果如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年11月20日
2024年11月20日
- 群星《一人一首成名曲》1998 台湾金碟珍藏版[WAV+CUE][1.1G]
- 陈百强2024-《凝望》头版限量编号MQA-UHQCD[WAV+CUE]
- 测试示范《监听天碟3》头版限量编号LECD[WAV+CUE]
- 陈瑞《爱你到天荒地老HQ》头版限量[低速原抓WAV+CUE]
- 徐小凤 《徐小凤殿堂18首》24K金碟[WAV+CUE]
- 保时捷原厂车载爆棚动态试音碟《Panamera_Soundtrack》DTS[WAV分轨][1G]
- 容祖儿《小小》香港首版 [WAV+CUE][1.1G]
- 莫文蔚《拉活…》SONY [WAV+CUE][1G]
- Beyond《极品天碟》LPCD45II首批限量版[WAV+CUE][1.7G]
- HIFI示范巅峰之作《情解药·Hi-Fi心魂》2CD[WAV+CUE]
- 房东的猫2021-关于彻夜不眠的事情(EP)[青柴文化][WAV+CUE]
- 群星.1993-一曲成名·青春无悔【飞碟】【WAV+CUE】
- 张芸京.2016-失败的高歌【泡耳音乐】【WAV+CUE】
- 天籁女声《2024第31届上海国际高端音影展纪念CD》[WAV+CUE][1.1G]
- 姚斯婷 《敢爱敢做》头版限量编号24K金碟[低速原抓WAV+CUE][1.2G]