Keras 3 API 文档 / 内置小型数据集 / MNIST 手写数字分类数据集

MNIST 数字分类数据集

[源代码]

load_data 函数

keras.datasets.mnist.load_data(path="mnist.npz")

加载 MNIST 数据集。

这是一个包含 60,000 张 28x28 灰度图像的 10 位数字数据集,以及 10,000 张图像的测试集。更多信息可以在 MNIST 主页找到。

参数

  • path: 在本地缓存数据集的路径(相对于 ~/.keras/datasets)。

返回

  • NumPy 数组元组(x_train, y_train), (x_test, y_test)

x_train: uint8 NumPy 数组,灰度图像数据,形状为 (60000, 28, 28),包含训练数据。像素值范围为 0 到 255。

y_train: uint8 NumPy 数组,数字标签(0-9 范围内的整数),形状为 (60000,),用于训练数据。

x_test: uint8 NumPy 数组,灰度图像数据,形状为 (10000, 28, 28),包含测试数据。像素值范围为 0 到 255。

y_test: uint8 NumPy 数组,数字标签(0-9 范围内的整数),形状为 (10000,),用于测试数据。

示例

(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
assert x_train.shape == (60000, 28, 28)
assert x_test.shape == (10000, 28, 28)
assert y_train.shape == (60000,)
assert y_test.shape == (10000,)

许可

Yann LeCun 和 Corinna Cortes 拥有 MNIST 数据集的版权,该数据集是原始 NIST 数据集的衍生作品。MNIST 数据集根据 知识共享署名-相同方式共享 3.0 许可的条款提供。