https://tensorflow.google.cn/tutorials/keras/classification

解决方案

from tensorflow import keras
import tensorflow as tf
import mnist_reader
import numpy as np
import matplotlib.pyplot as plt
(train_images, train_labels), (test_images, test_labels) = mnist_reader.load_data('../data/fashion')
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat','Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
train_images = train_images / 255.0test_images = test_images / 255.0plt.figure(figsize=(10,10))
for i in range(25):plt.subplot(5,5,i+1)plt.xticks([])plt.yticks([])plt.grid(False)plt.imshow(train_images[i], cmap=plt.cm.binary)plt.xlabel(class_names[train_labels[i]])
plt.show()model = keras.Sequential([keras.layers.Flatten(input_shape=(28, 28)),keras.layers.Dense(128, activation='relu'),keras.layers.Dense(10)
])
model.compile(optimizer='adam',loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=10)
test_loss, test_acc = model.evaluate(test_images,  test_labels, verbose=2)print('\nTest accuracy:', test_acc)
probability_model = tf.keras.Sequential([model,tf.keras.layers.Softmax()])
predictions = probability_model.predict(test_images)
print(predictions[0])
print(np.argmax(predictions[0]))
print(test_labels[0])def plot_image(i, predictions_array, true_label, img):predictions_array, true_label, img = predictions_array, true_label[i], img[i]plt.grid(False)plt.xticks([])plt.yticks([])plt.imshow(img, cmap=plt.cm.binary)predicted_label = np.argmax(predictions_array)if predicted_label == true_label:color = 'blue'else:color = 'red'plt.xlabel("{} {:2.0f}% ({})".format(class_names[predicted_label],100*np.max(predictions_array),class_names[true_label]),color=color)def plot_value_array(i, predictions_array, true_label):predictions_array, true_label = predictions_array, true_label[i]plt.grid(False)plt.xticks(range(10))plt.yticks([])thisplot = plt.bar(range(10), predictions_array, color="#777777")plt.ylim([0, 1])predicted_label = np.argmax(predictions_array)thisplot[predicted_label].set_color('red')thisplot[true_label].set_color('blue')i = 0
plt.figure(figsize=(6, 3))
plt.subplot(1, 2, 1)
plot_image(i, predictions[i], test_labels, test_images)
plt.subplot(1, 2, 2)
plot_value_array(i, predictions[i], test_labels)
plt.show()i = 12
plt.figure(figsize=(6,3))
plt.subplot(1,2,1)
plot_image(i, predictions[i], test_labels, test_images)
plt.subplot(1,2,2)
plot_value_array(i, predictions[i],  test_labels)
plt.show()# Plot the first X test images, their predicted labels, and the true labels.
# Color correct predictions in blue and incorrect predictions in red.
num_rows = 5
num_cols = 3
num_images = num_rows*num_cols
plt.figure(figsize=(2*2*num_cols, 2*num_rows))
for i in range(num_images):plt.subplot(num_rows, 2*num_cols, 2*i+1)plot_image(i, predictions[i], test_labels, test_images)plt.subplot(num_rows, 2*num_cols, 2*i+2)plot_value_array(i, predictions[i], test_labels)
plt.tight_layout()
plt.show()# Grab an image from the test dataset.
img = test_images[1]print(img.shape)# Add the image to a batch where it's the only member.
img = (np.expand_dims(img,0))print(img.shape)predictions_single = probability_model.predict(img)print(predictions_single)plot_value_array(1, predictions_single[0], test_labels)
_ = plt.xticks(range(10), class_names, rotation=45)print(np.argmax(predictions_single[0]))

参考文章

TensorFlow——本地加载fashion-mnist数据集

TensorFlow 教程——基本分类:对服装图像进行分类相关推荐

  1. TensorFlow 教程——手写数字识别

    运行环境 TensorFlow2.0 解决方案 from tensorflow import keras import tensorflow as tf import mnist_reader imp ...

  2. [转载] 使用Keras和TensorFlow 2.0建立深度学习模型对图像进行分类

    参考链接: Keras中的深度学习-建立深度学习模型 在本文中,我们将构建一个深度学习模型来对图像中的对象进行分类.为了构建卷积神经网络,我们将使用Kaggle提供的这个数据集.(https://ww ...

  3. 【五一创作】使用Resnet残差网络对图像进行分类(猫十二分类,模型定义、训练、保存、预测)(二)

    使用Resnet残差网络对图像进行分类 (猫十二分类,模型定义.训练.保存.预测)(二) 目录 (6).数据集划分 (7).训练集增强 (8).装载数据集 (9).初始化模型 (10).模型训练 (1 ...

  4. 【五一创作】使用Resnet残差网络对图像进行分类(猫十二分类,模型定义、训练、保存、预测)(一)

    使用Resnet残差网络对图像进行分类 (猫十二分类,模型定义.训练.保存.预测)(一) 目录 一.项目简介 二.环境说明 1.安装库 2.导入需要的库 三.分类过程 (1).解压数据集 (2).相关 ...

  5. TensorFlow 教程 --教程--2.6卷积神经网络

    注意: 本教程适用于对Tensorflow有丰富经验的用户,并假定用户有机器学习相关领域的专业知识和经验. 概述 对CIFAR-10 数据集的分类是机器学习中一个公开的基准测试问题,其任务是对一组32 ...

  6. [译] TensorFlow 教程 - 07 Inception 模型

    本文主要演示了如何使用Inception v3模型进行图像识别. 01 - 简单线性模型 | 02 - 卷积神经网络 | 03 - PrettyTensor | 04 - 保存& 恢复 05 ...

  7. TensorFlow教程之完整教程 2.7 字词的向量表示

     TensorFlow教程之完整教程 2.7 字词的向量表示 知与谁同 2017-08-22 15:37:40 浏览67 评论0 函数 摘要: 本文档为TensorFlow参考文档,本转载已得到T ...

  8. python tensorflow教程推荐_TensorFlow教程和文章推荐大全 -DZone AI

    在本文中,您将找到有关TensorFlow的所有文章集,TensorFlow 是  "用于机器学习的端到端开源平台".我们为刚开始使用基础知识的初学者提供了文章和教程,并且为真正想 ...

  9. 使用Python+OpenCV+Tensorflow+Flask实现检测X光图像中的COVID-19(新冠病毒)

    免责声明 本研究是为X光图像中COVID-19的自动检测而开发的,完全是为了教育目的.由于COVID-19没有经过专业或学术评估,最终的应用并不打算成为一个准确的用于诊断人类的COVID-19诊断系统 ...

最新文章

  1. 齐博cms 7.0 漏洞分析
  2. 也许MVC不该重写Url格式?
  3. wxWidgets:wxWebRequest 示例
  4. 【AI视野·今日CV 计算机视觉论文速览 第208期】Fri, 28 May 2021
  5. 物联网应用层协议选择和分析--MQTT、CoAP 、HTTP、XMPP、SoAP
  6. PlayWidget
  7. yacc 简易计算机规则,YACC 使用说明——计算器实例.pdf
  8. 致敬学习者丨黑马2020年度TOP榜视频教程,一键领!
  9. 【项目管理/PMP/第六版/新考纲】纯干货!项目发展史/项目定义/项目集/项目组合/十五至尊图
  10. Redis开发与运维之第五章持久化
  11. 诺顿防毒软件曝漏洞 任意下载运行恶意代码(转)
  12. python有什么游戏可以开发智力_用Python解“智力游戏”,你智商够吗?
  13. ie加载项存在残留是什么_残余IE加载项无法修复
  14. 电脑上微信怎么双开_【干货分享】电脑版微信怎么双开、多开~
  15. idea中加入插入当前系统日期快捷键
  16. 2019年严峻的就业形式 如何跳出被裁员的魔圈
  17. linux中的sh、dash、bash的区别
  18. php计算第几周,php计算当前是一年或一月中第几周的函数
  19. 微信小程序之时间计算器
  20. 如何离线下载网易云音乐

热门文章

  1. 正则表达式学习 (一) 转
  2. js参数使用时常犯的一个低级错误
  3. python制作好看的界面_【一点资讯】Python界面如何漂亮的展示树形结构,PyQt5控件之QTreeWidget详解 www.yidianzixun.com...
  4. python读取文件_python这么受欢迎,你知道如何以正确的方式来读取文件内容吗
  5. php如何制作视频特效,用PS将bmp图片制作出漂亮的动态视频效果
  6. mysql nosql 同步_使用canal和canal_mysql_nosql_sync同步mysql数据
  7. python接口自动化用例管理_python接口自动化测试(六)-unittest-单个用例管理
  8. python中字符移位加密_1.1 移位密码加密解密python实现
  9. 深度学习和目标检测系列教程 1-300:什么是对象检测和常见的8 种基础目标检测算法
  10. 十二、爬了CSDN,我发现了这些