TensorFlow2.0 测试Fashion_mnist数据集

前言

使用tensorflow的keras人工神经网络库对Fashion_mnist数据集进行分析,建模,测试。

Fashion_mnist数据集由十种类型的图片集组成
在这里插入图片描述

该数据集区使用标签来分类,用数字表示,分别是从0-9来表示标签
在这里插入图片描述

实际测试

import tensorflow as tf

if __name__ == '__main__':
    (train_image,train_label),(test_images,test_label) = tf.keras.datasets.fashion_mnist.load_data()
    #归一化处理
    train_image = train_image/255
    test_images = test_images/255
    #打印训练数据规模 结果为(60000, 28, 28),代表6w张图片
    print(train_image.shape)
    #引入模型
    model = tf.keras.Sequential()
    #把图像扁平成28*28的向量
    model.add(tf.keras.layers.Flatten(input_shape=(28,28)))
    #隐藏层
    model.add(tf.keras.layers.Dense(128,activation='relu'))
    #输出层,输出10个概率值,使用softmax把十个输出变成一个概率分布
    model.add(tf.keras.layers.Dense(10,activation='softmax'))
    #编译模型,规定优化方法和损失函数,当标签使用的是数字编码,使用sparse_categorical_crossentropy这个损失函数
    model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['acc'])
    #训练模型,次数为5
    model.fit(train_image,train_label,epochs=5)

    #在测试数据上,对我们的模型进行评价
    print(model.evaluate(test_images,test_label))

测试结果

得到损失和精确度

[0.3467264775753021, 0.8773]

视频学习网址

https://www.bilibili.com/video/av62215565?from=search&seid=13361627455677904834

发布了243 篇原创文章 · 获赞 106 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_43889841/article/details/104189813