pythonproject/.ipynb_checkpoints/image_classification_dataset-checkpoint.ipynb

107 lines
3.1 KiB
Plaintext
Raw Permalink Normal View History

2024-06-25 14:15:07 +08:00
{
"cells": [
{
"metadata": {},
"cell_type": "raw",
"source": "MNIST数据集 (LeCun et al., 1998) 是图像分类中广泛使用的数据集之一,但作为基准数据集过于简单。 我们将使用类似但更复杂的Fashion-MNIST数据集 (Xiao et al., 2017)。",
"id": "58ac648c45d06f50"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-05-19T04:24:31.687065Z",
"start_time": "2024-05-19T04:24:22.281131Z"
}
},
"cell_type": "code",
"source": [
"import tensorflow as tf\n",
"from d2l import tensorflow as d2l\n",
"\n",
"d2l.use_svg_display()"
],
"id": "4f19e5d16d0a7341",
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2024-05-19 12:24:22.318857: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA\n",
"To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
]
}
],
"execution_count": 1
},
{
"metadata": {},
"cell_type": "raw",
"source": [
"3.5.1. 读取数据集\n",
"我们可以通过框架中的内置函数将Fashion-MNIST数据集下载并读取到内存中。"
],
"id": "c67a3433075cb8ed"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "mnist_train, mnist_test = tf.keras.datasets.fashion_mnist.load_data()",
"id": "e5defd40322a3af2"
},
{
"metadata": {},
"cell_type": "raw",
"source": "Fashion-MNIST由10个类别的图像组成 每个类别由训练数据集train dataset中的6000张图像 和测试数据集test dataset中的1000张图像组成。 因此训练集和测试集分别包含60000和10000张图像。 测试数据集不会用于训练,只用于评估模型性能。",
"id": "9f2c0b217b6b5e30"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "len(mnist_train[0]), len(mnist_test[0])",
"id": "6129edd7e9c7e9fc"
},
{
"metadata": {},
"cell_type": "markdown",
"source": [
"每个输入图像的高度和宽度均为28像素。 数据集由灰度图像组成其通道数为1。 为了简洁起见,本书将高度\n",
"h像素、宽度w像素图像的形状记hxw或h,w。"
],
"id": "719bd9e11b3b06a9"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "mnist_train[0][0].shape",
"id": "3ed7450fafac4f36"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}