输入为命名形式为xxxx_m.jpg的图片
m为标签

import tensorflow  as tf
import os
from PIL import Image
import numpy as np
from matplotlib import pyplot as plt#np.set_printoptions(threshold=np.inf)
def generate(paths,image_list):data,label=[],[]for image in image_list:path=paths+'\\'+imageimg=Image.open(path)img=np.array(img.convert('L'))img=img/255.data.append(img)label.append(image[-5])data=np.array(data)label=np.array(label)label=label.astype(np.int64)return data,labelif os.path.exists('fashion_DNN_model.h5'):print('==============loading_model=============')type = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']model=tf.keras.models.load_model('fashion_DNN_model.h5')for filename in os.walk('exam_fashion'):#print(filename)exam_path='exam_fashion'for image in filename[2]:image_path=exam_path+'\\'+imageimg = Image.open(image_path)img = img.resize((28, 28), Image.ANTIALIAS)img_arr = np.array(img.convert('L'))img_arr = 255 - img_arr  # 每个像素点= 255 - 各自点当前灰度值img_arr = img_arr / 255.0test_data = img_arr[tf.newaxis, ...]ppred=model.predict(test_data)pred = tf.argmax(ppred, axis=1)print(image)print(type[int(pred)])else:train_path = 'fashion_image_label/fashion_train_jpg_60000'for filename in os.walk(train_path):train = filename[2]val_path = 'fashion_image_label/fashion_test_jpg_10000'for filename in os.walk(val_path):validation = filename[2]train_data, train_label = generate(train_path, train)val_data, val_label = generate(val_path, validation)# print(train_data.shape)# print(train_label.shape)model=tf.keras.models.Sequential([tf.keras.layers.Flatten(),tf.keras.layers.Dense(128,activation='relu'),tf.keras.layers.Dense(10,activation='softmax')])model.compile(optimizer='adam',loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),metrics=['accuracy'])#'categorical_crossentropy',history=model.fit(train_data,train_label,batch_size=32,epochs=20,validation_data=(val_data,val_label))model.summary()model.save('fashion_DNN_model.h5')acc = history.history['accuracy']val_acc = history.history['val_accuracy']loss = history.history['loss']val_loss = history.history['val_loss']plt.subplot(1, 2, 1)plt.plot(acc, label='Training Accuracy')plt.plot(val_acc, label='Validation Accuracy')plt.legend()plt.subplot(1, 2, 2)plt.plot(loss, label='Training Loss')plt.plot(val_loss, label='Validation Loss')plt.legend()# plt.savefig(plt_name)plt.show()

全连接网络实现Fashion数据集学习/预测相关推荐

  1. J. Cheminform. | 基于化学基因组学中深度和浅层学习预测药物特异性

    今天给大家介绍由巴黎文理研究大学计算生物研究中心的Veronique Stoven教授课题组发表在J Cheminform上的一篇文章.作者提出一种具有深度学习功能的化学基因组神经网络(CN),以分子 ...

  2. criteo 点击率预估_预处理criteo数据集以预测广告的点击率

    criteo 点击率预估 Amany Abdelhalim阿曼尼·阿卜杜勒哈林 Follow跟随 Sep 18 九月18 Preprocessing Criteo Dataset for Predic ...

  3. Cell | 深度突变学习预测SARS-CoV-2受体结合域组合突变对ACE2结合和抗体逃逸的影响...

    本文介绍一篇来自于苏黎世联邦理工学院的Joseph M. Taft在Cell上发表的工作--<Deep Mutational Learning Predicts ACE2 Binding and ...

  4. AI技术在气象领域应用方法:GFS数值模式的风速预报订正、台风预报数据智能订正、机器学习预测风电场的风功率、深度学习预测浅水方程模式、LSTM方法预测ENSO、深度学习convLSTM

    查看原文>>>Python人工智能在气象中的应用 Python是功能强大.免费.开源,实现面向对象的编程语言,在数据处理.科学计算.数学建模.数据挖掘和数据可视化方面具备优异的性能, ...

  5. 运用深度学习预测肺癌

    运用深度学习预测肺癌 原文:Forecasting Lung Cancer Diagnoses with Deep Learning 注:本文为The Data Science Bowl (DSB) ...

  6. MG-BERT | 利用 无监督 原子表示学习 预测分子性质 | 在分子图上应用BERT | GNN | 无监督学习(掩蔽原子预训练) | attention

    分子性质预测的的大部分文章,本质是研究分子的表示学习,然后应用到性质预测任务. 有分子性质预测的文章,关键词是"property prediction",也有专门研究毒性的文章,关 ...

  7. 使用SVM对分泌效应蛋白数据集进行分类预测

    1.SVM简介 支持向量机(Support Vector Machine, SVM)是一类按监督学习(supervised learning)方式对数据进行二元分类的广义线性分类器(generaliz ...

  8. Math/ML:序列监督学习-时间序列数据集/时间序列预测任务的简介、常用算法及其工具、案例应用之详细攻略

    Math/ML:序列监督学习-时间序列数据集/时间序列预测任务的简介.常用算法及其工具.案例应用之详细攻略 目录 序列学习/序列监督学习-时间序列数据集/时间序列预测任务的简介 1.序列学习/序列监督 ...

  9. 基于Keras搭建cifar10数据集训练预测Pipeline

    基于Keras搭建cifar10数据集训练预测Pipeline 钢笔先生关注 0.5412019.01.17 22:52:05字数 227阅读 500 Pipeline 本次训练模型的数据直接使用Ke ...

最新文章

  1. 【C#】第3章学习要点(三)--常用类和结构的用法
  2. 【实用】SAP Call Transaction下钻功能大全
  3. EOS page问题
  4. boost::noncopyable用法的测试程序
  5. git reset --hanrd撤回_一篇文章,全面掌握Git
  6. 如何快糙好猛的使用Shiqi.Yu老师的公开人脸检测库(附源码)
  7. 基本程序单元Activity—Activity生命周期之数据传递小程序
  8. meta http-equiv属性兼容浏览器_定时刷新
  9. 医疗:pacs(3)
  10. bootstrap validator 提供了哪些验证函数
  11. 阅读gulp源码小结
  12. java在win8闪退_解决Win8/Win8.1系统下的IE11闪退的六种方法
  13. 编程python视频教程_Python高级编程实战系列视频课程
  14. 自制Flash电子相册
  15. MySQL安装步骤【亲测可用】
  16. 《故障排除》——VMware Horizon agent:failed to install vmwusm driveer| winerror code 3758096967
  17. c语言英文数字变数字,[求助]阿拉伯数字变英文数字遇到的问题
  18. 菜鸡解析CSS(cascading style sheet)
  19. 简要比较费雪方程与剑桥方程
  20. 星际战魂java_星际战甲 专精聚魂选择推荐

热门文章

  1. java interface简写_JAVA开发中常见缩写(二)
  2. Matlab之inv函数
  3. HyperLedger Explorer 0.3.9环境搭建
  4. 《炬丰科技-半导体工艺》MEMS 应用中不同厚光刻胶的比较研究
  5. 天翼云打造国云安全品牌 铸牢企业云上安全防线
  6. python 中私有属性的设置方法案例:设置私有属性、利用函数get和set方法调用修改私有属性,并 用__str__的魔术方法打印,的具体案例
  7. 论文阅读Construction of Refined Protein Interaction Network for Predicting Essential Proteins
  8. c# workflow集成_将Google Wave与Windows Workflow集成
  9. 服务器cadence比虚拟机慢,Cadence版本选择浅见
  10. 求义隆单片机c语言红外解码程序,吐槽义隆单片机,顺便送上超轻红外解码程序....