当前位置: 首页 > news >正文

淘宝网网站建设的的意见校园微网站建设

淘宝网网站建设的的意见,校园微网站建设,wordpress后台极慢,编写网站方案设计书表格目录 1. 说明2. fashion_mnist的CNN模型测试2.1 导入相关库2.2 加载数据和模型2.3 设置保存图片的路径2.4 加载图片2.5 图片预处理2.6 对图片进行预测2.7 显示图片 3. 完整代码和显示结果4. 多张图片进行测试的完整代码以及结果 1. 说明 本篇文章是对上篇文章训练的模型进行测… 目录 1. 说明2. fashion_mnist的CNN模型测试2.1 导入相关库2.2 加载数据和模型2.3 设置保存图片的路径2.4 加载图片2.5 图片预处理2.6 对图片进行预测2.7 显示图片 3. 完整代码和显示结果4. 多张图片进行测试的完整代码以及结果 1. 说明 本篇文章是对上篇文章训练的模型进行测试。首先是将训练好的模型进行重新加载然后采用opencv对图片进行加载最后将加载好的图片输送给模型并且显示结果。 2. fashion_mnist的CNN模型测试 2.1 导入相关库 在这里导入需要的第三方库如cv2如果没有则需要自行下载。 from tensorflow import keras import skimage, os, sys, cv2 from PIL import ImageFont, Image, ImageDraw # PIL就是pillow包(保存图像) import numpy as np # 导入tensorflow import tensorflow as tf # 导入keras from tensorflow import keras from keras.datasets import fashion_mnist2.2 加载数据和模型 把fashion_mnist数据集进行加载并且把训练好的模型也加载进来。 # fashion数据集列表 class_names [T-shirt/top, Trouser, Pullover, Dress, Coat,Sandal, Shirt, Sneaker, Bag, Ankle boot] # 加载fashion数据 (x_train, y_train), (x_test, y_test) fashion_mnist.load_data() # 加载cnn_fashion.h5文件重新生成模型对象 recons_model keras.models.load_model(cnn_fashion.h5)2.3 设置保存图片的路径 将数据集的某个数据以图片的形式进行保存便于测试的可视化。 在这里设置图片存储的位置。 # 创建图片保存路径 test_file_path os.path.join(sys.path[0], imgs, test100.png) # 存储测试数据的任意一个 Image.fromarray(x_test[100]).save(test_file_path)在书写完上述代码后需要在代码的当前路径下新建一个imgs的文件夹用于存储图片如下。 执行完上述代码后就会在imgs的文件中可以发现多了一张图片如下(下面测试了很多次)。 2.4 加载图片 采用cv2对图片进行加载下面最后一行代码取一个通道的原因是用opencv库也就是cv2读取图片的时候图片是三通道的而训练的模型是单通道的因此取单通道。 # 加载本地test.png图像 image cv2.imread(test_file_path) # 复制图片 test_img image.copy() # 将图片大小转换成(28,28) test_img cv2.resize(test_img, (28, 28)) # 取单通道值 test_img test_img[:, :, 0]2.5 图片预处理 对图片进行预处理即进行归一化处理和改变形状处理这是为了便于将图片输入给训练好的模型进行预测。 # 预处理: 归一化 reshape new_test_img (test_img/255.0).reshape(1, 28, 28, 1)2.6 对图片进行预测 将图片输入给训练好我的模型并且进行预测。 预测的结果是10个概率值所以需要进行处理 np.argmax()是得到概率值最大值的序号也就是预测的数字。 # 预测 y_pre_pro recons_model.predict(new_test_img, verbose1) # 哪一类 class_id np.argmax(y_pre_pro, axis1)[0] print(test.png的预测概率, y_pre_pro) print(test.png的预测概率, y_pre_pro[0, class_id]) print(test.png的所属类别, class_names[class_id]) text str(class_names[class_id])2.7 显示图片 对预测的图片进行显示把预测的数字显示在图片上。 下面5行代码分别是创建窗口设定窗口大小显示图片停留图片清除内存。 # # 显示 cv2.namedWindow(img, 0) cv2.resizeWindow(img, 500, 500) # 自己设定窗口图片的大小 cv2.imshow(img, image) cv2.waitKey() cv2.destroyAllWindows()3. 完整代码和显示结果 以下是完整的代码和图片显示结果。 from tensorflow import keras import skimage, os, sys, cv2 from PIL import ImageFont, Image, ImageDraw # PIL就是pillow包(保存图像) import numpy as np # 导入tensorflow import tensorflow as tf # 导入keras from tensorflow import keras from keras.datasets import fashion_mnist # fashion数据集列表 class_names [T-shirt/top, Trouser, Pullover, Dress, Coat,Sandal, Shirt, Sneaker, Bag, Ankle boot] # 加载fashion数据 (x_train, y_train), (x_test, y_test) fashion_mnist.load_data() # 加载cnn_fashion.h5文件重新生成模型对象 recons_model keras.models.load_model(cnn_fashion.h5) # 创建图片保存路径 test_file_path os.path.join(sys.path[0], imgs, test100.png) # 存储测试数据的任意一个 Image.fromarray(x_test[100]).save(test_file_path) # 加载本地test.png图像 image cv2.imread(test_file_path) # 复制图片 test_img image.copy() # 将图片大小转换成(28,28) test_img cv2.resize(test_img, (28, 28)) # 取单通道值 test_img test_img[:, :, 0] # 预处理: 归一化 reshape new_test_img (test_img/255.0).reshape(1, 28, 28, 1) # 预测 y_pre_pro recons_model.predict(new_test_img, verbose1) # 哪一类 class_id np.argmax(y_pre_pro, axis1)[0] print(test.png的预测概率, y_pre_pro) print(test.png的预测概率, y_pre_pro[0, class_id]) print(test.png的所属类别, class_names[class_id]) text str(class_names[class_id]) # # 显示 cv2.namedWindow(img, 0) cv2.resizeWindow(img, 500, 500) # 自己设定窗口图片的大小 cv2.imshow(img, image) cv2.waitKey() cv2.destroyAllWindows() To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 1/1 [] - 0s 168ms/step test.png的预测概率 [[2.9672831e-04 7.3040414e-05 1.4721525e-04 9.9842703e-01 4.7597905e-068.9959512e-06 1.0416918e-03 8.6147125e-09 4.2549357e-07 1.2974965e-07]] test.png的预测概率 0.99842703 test.png的所属类别 Dress4. 多张图片进行测试的完整代码以及结果 为了测试更多的图片引入循环进行多次测试效果更好。 from tensorflow import keras from keras.datasets import fashion_mnist import skimage, os, sys, cv2 from PIL import ImageFont, Image, ImageDraw # PIL就是pillow包(保存图像) import numpy as np# fashion数据集列表 class_names [T-shirt/top, Trouser, Pullover, Dress, Coat,Sandal, Shirt, Sneaker, Bag, Ankle boot] # 加载mnist数据 (x_train, y_train), (x_test, y_test) fashion_mnist.load_data() # 加载cnn_fashion.h5文件重新生成模型对象 recons_model keras.models.load_model(cnn_fashion.h5)prepicture int(input(input the number of test picture :)) for i in range(prepicture):path1 input(input the test picture path:)# 创建图片保存路径test_file_path os.path.join(sys.path[0], imgs, path1)# 存储测试数据的任意一个num int(input(input the test picture num:))Image.fromarray(x_test[num]).save(test_file_path)# 加载本地test.png图像image cv2.imread(test_file_path)# 复制图片test_img image.copy()# 将图片大小转换成(28,28)test_img cv2.resize(test_img, (28, 28))# 取单通道值test_img test_img[:, :, 0]# 预处理: 归一化 reshapenew_test_img (test_img/255.0).reshape(1, 28, 28, 1)# 预测y_pre_pro recons_model.predict(new_test_img, verbose1)# 哪一类数字class_id np.argmax(y_pre_pro, axis1)[0]print(test.png的预测概率, y_pre_pro)print(test.png的预测概率, y_pre_pro[0, class_id])print(test.png的所属类别, class_names[class_id])text str(class_names[class_id])# # 显示cv2.namedWindow(img, 0)cv2.resizeWindow(img, 500, 500) # 自己设定窗口图片的大小cv2.imshow(img, image)cv2.waitKey()cv2.destroyAllWindows() To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. input the number of test picture :2 input the test picture path:101.jpg input the test picture num:1 1/1 [] - 0s 145ms/step test.png的预测概率 [[5.1000708e-05 2.9449904e-13 9.9993873e-01 5.5402721e-11 4.8696438e-061.2649738e-12 5.3379590e-06 6.5959898e-17 7.1223938e-10 4.0113624e-12]] test.png的预测概率 0.9999387 test.png的所属类别 Pulloverinput the test picture path:102.jpg input the test picture num:2 1/1 [] - 0s 21ms/step test.png的预测概率 [[3.01315001e-10 1.00000000e00 1.03142118e-14 8.63922683e-114.10812981e-11 6.07313693e-22 2.31636132e-09 5.08595438e-251.02018335e-13 8.82350167e-28]] test.png的预测概率 1.0 test.png的所属类别 Trouser
http://www.w-s-a.com/news/192094/

相关文章:

  • 小说网站建设之前需求分析免费下载京东购物
  • 园林景观设计案例网站wordpress 文章内容页
  • 网站什么做才会更吸引客户楚雄网站开发rewlkj
  • 电商网站构建预算方案视频制作网站怎么做
  • 包装设计灵感网站ps软件下载电脑版多少钱
  • 手机网站图片做多大原网站开发新功能
  • 网站设计培训成都陕西网站建设公司哪有
  • expedia电子商务网站建设辽宁网站设计
  • 深圳网站建设网站运营绥芬河市建设局网站
  • 家政服务网站做推广有效果吗做图软件ps下载网站有哪些
  • 北京市建设教育协会网站flash网站制作单选框和复选框ui组件
  • 国外有没有做问卷调查的网站网站网页怎么做
  • 简单个人网站模板下载网站建设整体情况介绍
  • 网站建设做到哪些内容荆门网站建设电话咨询
  • 玉树网站建设公司双11主机 wordpress 2015
  • dw做网站背景图片设置汕头seo管理
  • 个人又什么办法做企业网站唐山哪里建轻轨和地铁
  • 手机网站404页面室内设计公司排名前100
  • 做民宿需要和多家网站合作吗创建软件的步骤
  • 网站导航栏设计要求辽宁省住房和城乡建设厅
  • 海外网站平台腾讯营销平台
  • 东道网站建设良品铺子网络营销案例
  • 免费企业查询软件优化模型
  • 兰亭集势的网站平台建设凡科网站免费版怎么做
  • 在网站做推广要钱吗网站根目录是哪个文件夹
  • 网站建设如何弄链接海外vps一键配置WordPress
  • 1个ip可以做几个网站吗动画制作可以自学吗
  • 顺德建设局网站如何搭建网站
  • 精品网站建设费用 干净磐石网络网页制作简单作业
  • 网站建设需要用软件群晖怎样做网站