Dataset之CIFAR-10:CIFAR-10数据集的简介、下载、使用方法之详细攻略

Dataset之CIFAR-10:CIFAR-10数据集的简介、下载、使用方法之详细攻略

目录

CIFAR-10的简介

1、与MNIST 数据集中目比, CIFAR-10 真高以下不同点

2、TensorFlow 官方示例的CIFAR-10 代码文件

3、CIFAR-10 数据集的数据文件名及用途

4、基于CIFAR-10数据集最新算法预测准确率对比

CIFAR-10的下载

1、下载CIFAR-10 数据集的全部数据

CIFAR-10使用方法

1、使用TF读取CIFAR-10 数据


CIFAR-10的简介

官网链接The CIFAR-10 dataset

          CIFAR-10是一个更接近普适物体的彩色图像数据集。CIFAR-10 是由Hinton 的学生Alex Krizhevsky 和Ilya Sutskever 整理的一个用于识别普适物体的小型数据集。一共包含10 个类别的RGB 彩色图片:飞机( airplane )、汽车( automobile )、鸟类( bird )、猫( cat )、鹿( deer )、狗( dog )、蛙类( frog )、马( horse )、船( ship )和卡车( truck )。
         每个图片的尺寸为32 × 32 ,每个类别有6000个图像,数据集中一共有50000 张训练图片和10000 张测试图片。

1、与MNIST 数据集中目比, CIFAR-10 真高以下不同点

  • (1)、CIFAR-10 是3 通道的彩色RGB 图像,而MNIST 是灰度图像
  • (2)、CIFAR-10 的图片尺寸为32 × 32 , 而MNIST 的图片尺寸为28 × 28 ,比MNIST 稍大。
  • (3)、相比于手写字符, CIFAR-10 含有的是现实世界中真实的物体,不仅噪声很大,而且物体的比例、特征都不尽相同,这为识别带来很大困难。直接的线性模型如Softmax 在CIFAR-10 上表现得很差。

2、TensorFlow 官方示例的CIFAR-10 代码文件

3、CIFAR-10 数据集的数据文件名及用途

     在CIFAR-10 数据集中,文件data_batch_1.bin、data_batch_2.bin 、··data_batch_5.bin 和test_ batch.bin 中各有10000 个样本。一个样本由3073 个字节组成,第一个字节为标签label ,剩下3072 个字节为图像数据。样本和样本之间没高多余的字节分割, 因此这几个二进制文件的大小都是30730000 字节。

文件名

文件用途

batches.meta. bet

文件存储了每个类别的英文名称。可以用记事本或其他文本文件阅读器打开浏览查看

data batch I.bin 、

data batch 2.bm 、

……

data batch 5.bin

这5 个文件是CIFAR- 10 数据集中的训练数据。每个文件以二进制格式存储了10000 张32 × 32 的彩色图像和这些图像对应的类别标签。一共50000 张训练图像

test batch.bin

这个文件存储的是测试图像和测试图像的标签。一共10000 张

readme.html

数据集介绍文件

4、基于CIFAR-10数据集最新算法预测准确率对比

 相关链接Classification datasets results

CIFAR-10的下载

1、下载CIFAR-10 数据集的全部数据

FLAGS = tf.app.flags.FLAGS          
cifar10.maybe_download_and_extract() 


>> Downloading cifar-10-binary.tar.gz 0.0%
……
>> Downloading cifar-10-binary.tar.gz 0.0%
>> Downloading cifar-10-binary.tar.gz 0.1%
……
>> Downloading cifar-10-binary.tar.gz 0.1%
>> Downloading cifar-10-binary.tar.gz 0.2%
……
>> Downloading cifar-10-binary.tar.gz 0.2%
>> Downloading cifar-10-binary.tar.gz 0.3%
……
>> Downloading cifar-10-binary.tar.gz 98.9%
……
>> Downloading cifar-10-binary.tar.gz 99.0%
……
>> Downloading cifar-10-binary.tar.gz 100.0%
Successfully downloaded cifar-10-binary.tar.gz 170052171 bytes.

CIFAR-10使用方法

1、使用TF读取CIFAR-10 数据

  • (1)、用tf.train.string_ input producer 建立队列。
  • (2)、通过reader.read 读数据。一个文件就是一张图片,因此用的reader 是tf.WholeFileReader()。CIFAR-10 数据是以固定字节存在文件中的,一个文件中含再多个样本,因此不能使用tf. WholeFileReader (),而是用tf.FixedLengthRecordReader() 。
  • (3)、调用tf. train . start_ queue_ runners 。
  • (4)、最后,通过sess.run()取出图片结果。

相关文章

TF:利用TF读取数据操作,将CIFAR-10 数据集中的训练图片读取出来,并保存为.jpg 格式

GoogLeNet是一个深度卷积神经网络,它在2014年ImageNet大规模视觉识别竞赛(ILSVRC)上获得了冠军。以下是一个使用GoogLeNet进行CIFAR-10分类任务的示例代码。 首先,我们需要导入必要的库:TensorFlow和Keras。 ```python import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers ``` 然后,我们可以定义GoogLeNet网络。GoogLeNet由多个“Inception”模块组成,每个模块都有多个分支,包含不同大小的卷积和池化操作。下面是一个包含3个Inception模块的简单实现。 ```python def create_googlenet(): input_shape = (32, 32, 3) # Input layer inputs = keras.Input(shape=input_shape) # First convolutional layer x = layers.Conv2D(filters=64, kernel_size=7, strides=2, padding="same", activation="relu")(inputs) x = layers.MaxPooling2D(pool_size=3, strides=2, padding="same")(x) # First Inception module x = inception_module(x, filters=[64, 96, 128, 16, 32, 32]) # Second Inception module x = inception_module(x, filters=[128, 128, 192, 32, 96, 64]) x = layers.MaxPooling2D(pool_size=3, strides=2, padding="same")(x) # Third Inception module x = inception_module(x, filters=[192, 96, 208, 16, 48, 64]) # Output layer x = layers.GlobalAveragePooling2D()(x) outputs = layers.Dense(units=10, activation="softmax")(x) # Create model model = keras.Model(inputs=inputs, outputs=outputs, name="googlenet") return model ``` Inception模块可以使用以下代码实现: ```python def inception_module(inputs, filters): f1, f3r, f3, f5r, f5, fp = filters # 1x1 convolution branch conv1 = layers.Conv2D(filters=f1, kernel_size=1, activation="relu")(inputs) # 3x3 convolution branch conv3r = layers.Conv2D(filters=f3r, kernel_size=1, activation="relu")(inputs) conv3 = layers.Conv2D(filters=f3, kernel_size=3, padding="same", activation="relu")(conv3r) # 5x5 convolution branch conv5r = layers.Conv2D(filters=f5r, kernel_size=1, activation="relu")(inputs) conv5 = layers.Conv2D(filters=f5, kernel_size=5, padding="same", activation="relu")(conv5r) # Max pooling branch pool = layers.MaxPooling2D(pool_size=3, strides=1, padding="same")(inputs) pool_conv = layers.Conv2D(filters=fp, kernel_size=1, activation="relu")(pool) # Concatenate branches outputs = layers.Concatenate()([conv1, conv3, conv5, pool_conv]) return outputs ``` 最后,我们可以编译和训练模型。 ```python # Load CIFAR-10 dataset (x_train, y_train), (x_test, y_test) = keras.datasets.cifar10.load_data() # Normalize pixel values x_train = x_train.astype("float32") / 255.0 x_test = x_test.astype("float32") / 255.0 # Convert labels to one-hot vectors y_train = keras.utils.to_categorical(y_train, 10) y_test = keras.utils.to_categorical(y_test, 10) # Create model model = create_googlenet() # Compile model model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"]) # Train model model.fit(x_train, y_train, batch_size=128, epochs=50, validation_data=(x_test, y_test)) ``` 在训练完成后,我们可以使用以下代码评估模型的性能。 ```python # Evaluate model test_loss, test_acc = model.evaluate(x_test, y_test) print("Test accuracy:", test_acc) ```
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个处女座的程序猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值