MNIST
收藏数据集概述
数据集列表
数据集使用示例
-
Python 代码示例: python import tensorflow_datasets as tfds import tensorflow as tf
查看可用数据集
print(tfds.list_builders())
加载数据集
ds_train = tfds.load(name="mnist", split="train", shuffle_files=True)
构建输入管道
ds_train = ds_train.shuffle(1000).batch(128).prefetch(10) for features in ds_train.take(1): image, label = features["image"], features["label"]
数据集构建器 (DatasetBuilder)
-
功能: 所有数据集实现为
tfds.core.DatasetBuilder的子类。 -
使用方法: python import tensorflow_datasets as tfds
mnist_builder = tfds.builder(mnist) mnist_builder.download_and_prepare() ds = mnist_builder.as_dataset(split=train) info = mnist_builder.info
数据集信息 (DatasetInfo)
-
示例: MNIST 数据集信息
tfds.core.DatasetInfo( name=mnist, version=1.0.0, description=The MNIST database of handwritten digits., homepage=http://yann.lecun.com/exdb/mnist/, features=FeaturesDict({ image: Image(shape=(28, 28, 1), dtype=tf.uint8), label: ClassLabel(shape=(), dtype=tf.int64, num_classes=10) }, total_num_examples=70000, splits={ test: <tfds.core.SplitInfo num_examples=10000>, train: <tfds.core.SplitInfo num_examples=60000> }, supervised_keys=(image, label), citation=..., )
NumPy 使用
- 功能: 使用
tfds.as_numpy从tf.data.Dataset返回生成器,生成 NumPy 数组记录。 - 使用方法: python train_ds = tfds.load("mnist", split="train") train_ds = train_ds.shuffle(1024).batch(128).repeat(5).prefetch(10) for example in tfds.as_numpy(train_ds): numpy_images, numpy_labels = example["image"], example["label"]
引用信息
-
引用格式:
@misc{TFDS, title = {{TensorFlow Datasets}, A collection of ready-to-use datasets}, howpublished = {url{https://www.tensorflow.org/datasets}}, }
请求新数据集
- 请求方式: 通过 GitHub 问题 提交数据集请求。




