minist数据集的获取方法

在官网下载minist数据集,速度感人。因此特意上传了一份,供需要的朋友下载:minist数据集
第一次打开这个数据集,也是一脸懵,不过还好,脱坑代码如下:

import numpy as np
import os

# 训练集
with open('./minist_data/train-images.idx3-ubyte') as f:
    loaded = np.fromfile(file = f, dtype = np.uint8)
    train_data = loaded[16:].reshape((60000, 784))
print(train_data.shape) # (60000, 784)


with open('./minist_data/train-labels.idx1-ubyte') as f:
    loaded = np.fromfile(file = f, dtype = np.uint8)
    train_labels = loaded[8:]
print(train_labels.shape) # (60000,)


# 测试集
with open('./minist_data/t10k-images.idx3-ubyte') as f:
    loaded = np.fromfile(file=f, dtype=np.uint8)
    test_data = loaded[16:].reshape((10000, 784))
print(test_data.shape) # (10000, 784)

with open('./minist_data/t10k-labels.idx1-ubyte') as f:
    loaded = np.fromfile(file=f, dtype=np.uint8)
    test_labels = loaded[8:].reshape((10000))
print(test_labels.shape) # (10000,)

可以看到,训练集有六万条样本,784个特征。测试集一万条样本。

你可能感兴趣的:(tensorflow)