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

查网站域名备案价格重庆建设监理协会

查网站域名备案价格,重庆建设监理协会,什么样建广告网站,辽宁建设工程信息网上传招标文件方法目录 1. 说明2. 猫狗大战的CNN模型测试2.1 导入相关库2.2 加载模型2.3 设置保存图片的路径2.4 加载图片2.5 图片预处理2.6 对图片进行预测2.7 显示图片 3. 完整代码和显示结果4. 多张图片进行测试的完整代码以及结果 1. 说明 本篇文章是对上篇文章猫狗大战训练的模型进行测试。… 目录 1. 说明2. 猫狗大战的CNN模型测试2.1 导入相关库2.2 加载模型2.3 设置保存图片的路径2.4 加载图片2.5 图片预处理2.6 对图片进行预测2.7 显示图片 3. 完整代码和显示结果4. 多张图片进行测试的完整代码以及结果 1. 说明 本篇文章是对上篇文章猫狗大战训练的模型进行测试。首先是将训练好的模型进行重新加载然后采用opencv对图片进行加载最后将加载好的图片输送给模型并且显示结果。 2. 猫狗大战的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 keras2.2 加载模型 把训练好的模型也加载进来这里不用加载数据因为数据是自制的。 # 加载my_cnn_cat_dog_3.h5文件重新生成模型对象 recons_model keras.models.load_model(my_cnn_cat_dog_3.h5)2.3 设置保存图片的路径 将数据集的某个数据以图片的形式进行保存便于测试的可视化这里在之前已经分了测试集因此设置图片路径即可。 在这里设置图片存储的位置便于将图片进行存储。 # 创建图片保存路径 test_file_path os.path.join(dog-cats, test, 1.jpg) # 加载本地test.png图像 image cv2.imread(test_file_path)上述代码是将test文件夹里面的1.jpg进行测试如果想测试其它的只需改为x.jpg即可。 2.4 加载图片 采用cv2对图片进行加载用opencv库也就是cv2读取图片的时候图片是三通道的而训练的模型是三通道的因此不只用取单通道而是三通道这里和之前的灰度图不同。 # 复制图片 test_img image.copy() # 将图片大小转换成(150,150) test_img cv2.resize(test_img, (150,150))2.5 图片预处理 对图片进行预处理即进行归一化处理和改变形状处理这是为了便于将图片输入给训练好的模型进行预测。因此在这里将形状改变为1501503的前面的1是样本数所以是(1,150,150,3)。 # 预处理: 归一化 reshape new_test_img (test_img/255.0).reshape(1, 150,150, 3)2.6 对图片进行预测 将图片输入给训练好我的模型并且进行预测。 因为是二分类所以预测的结果是1个概率值所以需要进行处理 大于0.5的是狗小于0.5的是猫。 # 预测 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]) if y_pre_pro[0, class_id] 0.5:print(png的所属类别, dog) else:print(png的所属类别, cat)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# 加载my_cnn_cat_dog_3.h5文件重新生成模型对象 recons_model keras.models.load_model(my_cnn_cat_dog_3.h5) # 创建图片保存路径 test_file_path os.path.join(dog-cats, test, 1.jpg) # 加载本地test.png图像 image cv2.imread(test_file_path) # 复制图片 test_img image.copy() # 将图片大小转换成(150,150) test_img cv2.resize(test_img, (150,150)) # 预处理: 归一化 reshape new_test_img (test_img/255.0).reshape(1, 150,150, 3) # 预测 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]) if y_pre_pro[0, class_id] 0.5:print(png的所属类别, dog) else:print(png的所属类别, cat) # # 显示 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 [] - 3s 3s/step test.png的预测概率 [[0.999939]] test.png的预测概率 0.999939 png的所属类别 dog4. 多张图片进行测试的完整代码以及结果 为了测试更多的图片引入循环进行多次测试效果更好。 from tensorflow import keras from keras.datasets import cifar10 import skimage, os, sys, cv2 from PIL import ImageFont, Image, ImageDraw # PIL就是pillow包(保存图像) import numpy as np# 加载my_cnn_cat_dog_3.h5文件重新生成模型对象 recons_model keras.models.load_model(my_cnn_cat_dog_3.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(dog-cats, test, path1)# 加载本地test.png图像image cv2.imread(test_file_path)# 复制图片test_img image.copy()# 将图片大小转换成(150,150)test_img cv2.resize(test_img, (150, 150))# 预处理: 归一化 reshapenew_test_img (test_img / 255.0).reshape(1, 150, 150, 3)# 预测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])if y_pre_pro[0, class_id] 0.5:print(png的所属类别, dog)else:print(png的所属类别, cat)# # 显示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:2.jpg 1/1 [] - 2s 2s/step test.png的预测概率 [[0.99774814]] test.png的预测概率 0.99774814 png的所属类别 doginput the test picture path:3.jpg 1/1 [] - 0s 87ms/step test.png的预测概率 [[0.9999783]] test.png的预测概率 0.9999783 png的所属类别 dog
http://www.hkea.cn/news/14393757/

相关文章:

  • 金山企业型网站建设国际网站建设与维护
  • 江西省网站建设公司怎么用网站做word文件
  • 青浦区网站建设费用北滘网站建设
  • 网站建设工作建议企业网站制作公司推荐
  • 电商类网站开发方案谷歌下载
  • p2p网站建设规划国家对于学校网站建设
  • 九龙坡建站公司简洁的企业网站源码
  • 著名的设计企业网站网站建设项目实践
  • 网站建设国外拂去其安卓软件开发培训机构
  • 中山市开发区建设局网站建立购物网站 app
  • 济南企业网站厦门住房建设局网站首页
  • 网校网站建设多少钱中国企业大黄页
  • 网站后台不能上传图片字体
  • 俄文网站建设方案天津网站制作培训
  • wordpress postviewsseo交流中心
  • 建站兔软件常见问题专业seo公司
  • 建设一个网站需要学哪些flash源码网站
  • 万网注册域名做简单网站北京网站seo排名
  • 资产负债表在哪个网站可以做dz论坛怎么做视频网站
  • 中国上海网站首页自己做网站nas
  • 做门户网站用什么技术好高端网站建设好处
  • 只做特卖的网站网站建设平台怎么样
  • 河源网站网站建设大连网站排名公司
  • 网站设计制作的服务机构大连在建项目
  • 广西网站建设制作模板设计应考虑哪些荷载
  • 建一个网络商城的网站素材搜集预算是什么济南网站制作建设
  • 做近代史纲要题的网站如何设计一个实验方案
  • 企业网站改版升级重庆卓光科技有限公司
  • 网站内容管理咨询公司注册资本
  • 外贸网站翻译建设服务 好的网站制作