下载

Fashion-mnist数据集下载:

[大小]:29.45MB

[链接]:https://pan.baidu.com/s/1EjE1Jjgk8tRwncYZWV3I-Q

[提取码]:qiwk

简介

Fashion-mnist数据集包括60000张训练图像和10000张测试图像,共有10个服装类别(0~9),每张图像均为28x28的单通道灰度图像

标签与服装的对应关系如下:

  • 0 T-shirt/top

  • 1 Trouser

  • 2 Pullover

  • 3 Dress

  • 4 Coat

  • 5 Sandal

  • 6 Shirt

  • 7 Sneaker

  • 8 Bag

  • 9 Ankle boot

数据集调用

1. 通过keras调用

keras首次调用时会进行fashion-mnist数据集的下载,若下载速度过慢,可以将云盘中获得的fashion-mnist文件夹置于keras指定目录下(win10):

'C:\Users\xxx\.keras\datasets'

from keras.datasets import fashion_mnistimport matplotlib.pyplot as plt(x_train,y_train),(x_test,y_test)=fashion_mnist.load_data()for i in range(1,101):    plt.subplot(10,10,i)    plt.imshow(x_train[i],'gray')    plt.axis('off')plt.show()

结果显示如下:

图片

2. 通过python调用

import numpy as npimport osimport gziproot_dir = 'E:\\微信公众号素材\\datasets\\fashion-mnist'for root, dirs, files in os.walk(root_dir):    for file in files:        decom_filename = file.replace('.gz', '')        f=gzip.open(os.path.join(root,file))        with open(os.path.join(root, decom_filename), 'wb') as newfile:            newfile.write(f.read())        f.close()

def load_data():    files = ['train-labels-idx1-ubyte', 'train-images-idx3-ubyte',                 't10k-labels-idx1-ubyte', 't10k-images-idx3-ubyte']    with open(os.path.join(root_dir, files[0]), 'rb') as f:        y_train=np.frombuffer(f.read(), 'uint8', offset=8)    with open(os.path.join(root_dir, files[1]),'rb') as f:        x_train=np.frombuffer(f.read(), 'uint8', offset=16).reshape(len(y_train), 28, 28)    with open(os.path.join(root_dir, files[2]), 'rb') as f:        y_test=np.frombuffer(f.read(), 'uint8', offset=8)    with open(os.path.join(root_dir, files[3]), 'rb') as f:        x_test=np.frombuffer(f.read(), 'uint8', offset=16).reshape(len(y_test), 28, 28)    return (x_train, y_train), (x_test, y_test)

if __name__ == '__main__':    import matplotlib.pyplot as plt    (x_train, y_train), (x_test, y_test) = load_data()    for i in range(1, 101):        plt.subplot(10, 10, i)        plt.imshow(x_train[i-1], 'gray')        plt.axis('off')    plt.show()

结果同样显示如下:

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐