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

叮当设计网快速网站seo效果

叮当设计网,快速网站seo效果,怎样做公司网站建设,建邺做网站价格目录 1. 说明2. IKUN模型的CNN模型测试2.1 导入相关库2.2 加载模型2.3 设置保存图片的路径2.4 加载图片2.5 图片预处理2.6 对图片进行预测2.7 显示图片 3. 完整代码和显示结果4. 多张图片进行测试的完整代码以及结果 1. 说明 本篇文章是对上篇文章猫狗大战训练的模型进行测试。…

目录

  • 1. 说明
  • 2. IKUN模型的CNN模型测试
    • 2.1 导入相关库
    • 2.2 加载模型
    • 2.3 设置保存图片的路径
    • 2.4 加载图片
    • 2.5 图片预处理
    • 2.6 对图片进行预测
    • 2.7 显示图片
  • 3. 完整代码和显示结果
  • 4. 多张图片进行测试的完整代码以及结果

1. 说明

本篇文章是对上篇文章猫狗大战训练的模型进行测试。首先是将训练好的模型进行重新加载,然后采用opencv对图片进行加载,最后将加载好的图片输送给模型并且显示结果。

2. IKUN模型的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

2.2 加载模型

把训练好的模型也加载进来,这里不用加载数据,因为数据是自制的。

# 加载my_ikun.h5文件,重新生成模型对象
recons_model = keras.models.load_model('my_ikun.h5')

2.3 设置保存图片的路径

将数据集的某个数据以图片的形式进行保存,便于测试的可视化,这里在之前已经分了测试集,因此设置图片路径即可。
在这里设置图片存储的位置,便于将图片进行存储。

# 创建图片保存路径
test_file_path = os.path.join(sys.path[0], 'imgs', 'test1', '4.jpg')

上述代码是将test文件夹里面的4.jpg进行测试,如果想测试其它的只需改为x.jpg即可。
在这里插入图片描述

2.4 加载图片

采用cv2对图片进行加载,用opencv库也就是cv2读取图片的时候,图片是三通道的,而训练的模型是三通道的,因此不只用取单通道,而是三通道,这里和之前的灰度图不同。

# 加载本地test.png图像
image = cv2.imread(test_file_path)
# 复制图片
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, verbose=1)
# 哪一类
class_id = np.argmax(y_pre_pro, axis=1)[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的所属类别:', '坤哥')
else:print('png的所属类别:', '鸡哥')

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_ikun.h5文件,重新生成模型对象
recons_model = keras.models.load_model('my_ikun.h5')
# 创建图片保存路径
test_file_path = os.path.join(sys.path[0], 'imgs', 'test1', '4.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, verbose=1)
# 哪一类
class_id = np.argmax(y_pre_pro, axis=1)[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的所属类别:', '坤哥')
else:print('png的所属类别:', '鸡哥')
# # 显示
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 315ms/step
test.png的预测概率: [[1.]]
test.png的预测概率: 1.0
png的所属类别: 坤哥

在这里插入图片描述

4. 多张图片进行测试的完整代码以及结果

为了测试更多的图片,引入循环进行多次测试,效果更好。

from tensorflow import keras
import skimage, os, sys, cv2
from PIL import ImageFont, Image, ImageDraw  # PIL就是pillow包(保存图像)
import numpy as np# 加载my_ikun.h5文件,重新生成模型对象
recons_model = keras.models.load_model('my_ikun.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('imgs', 'test1', 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, verbose=1)# 哪一类数字class_id = np.argmax(y_pre_pro, axis=1)[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的所属类别:', '坤哥')else:print('png的所属类别:', '鸡哥')# # 显示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:3.jpg
1/1 [==============================] - 0s 170ms/step
test.png的预测概率: [[0.99739295]]
test.png的预测概率: 0.99739295
png的所属类别: 坤哥

在这里插入图片描述

input the test picture path:10.jpg
1/1 [==============================] - 0s 163ms/step
test.png的预测概率: [[0.09064844]]
test.png的预测概率: 0.09064844
png的所属类别: 鸡哥

在这里插入图片描述


文章转载自:
http://calyptra.c7627.cn
http://pycnocline.c7627.cn
http://epibiont.c7627.cn
http://teabowl.c7627.cn
http://dontopedalogy.c7627.cn
http://rhomboidal.c7627.cn
http://crystalligerous.c7627.cn
http://pieplant.c7627.cn
http://apropos.c7627.cn
http://postern.c7627.cn
http://additive.c7627.cn
http://gamma.c7627.cn
http://indict.c7627.cn
http://moab.c7627.cn
http://dyspnea.c7627.cn
http://fifteen.c7627.cn
http://cystine.c7627.cn
http://numberless.c7627.cn
http://nola.c7627.cn
http://jabberwocky.c7627.cn
http://adequately.c7627.cn
http://semicontinua.c7627.cn
http://achromobacter.c7627.cn
http://culdotomy.c7627.cn
http://dianoetic.c7627.cn
http://obtrusively.c7627.cn
http://rainwater.c7627.cn
http://batik.c7627.cn
http://repertory.c7627.cn
http://tamale.c7627.cn
http://hypergolic.c7627.cn
http://sylph.c7627.cn
http://inspector.c7627.cn
http://isoantibody.c7627.cn
http://hieratical.c7627.cn
http://zebroid.c7627.cn
http://brittonic.c7627.cn
http://lammister.c7627.cn
http://administrant.c7627.cn
http://kindless.c7627.cn
http://mazut.c7627.cn
http://thixotropic.c7627.cn
http://condolatory.c7627.cn
http://microoperation.c7627.cn
http://silvester.c7627.cn
http://moniliasis.c7627.cn
http://corridor.c7627.cn
http://galvanometry.c7627.cn
http://radically.c7627.cn
http://rowing.c7627.cn
http://kleptomaniac.c7627.cn
http://denationalization.c7627.cn
http://posteriad.c7627.cn
http://exodium.c7627.cn
http://foretoken.c7627.cn
http://externe.c7627.cn
http://rectangularity.c7627.cn
http://zi.c7627.cn
http://subtotalled.c7627.cn
http://ems.c7627.cn
http://tumblerful.c7627.cn
http://lethiferous.c7627.cn
http://securely.c7627.cn
http://seclusively.c7627.cn
http://metalliding.c7627.cn
http://proletcult.c7627.cn
http://governess.c7627.cn
http://aberration.c7627.cn
http://primogenial.c7627.cn
http://tootsy.c7627.cn
http://nidus.c7627.cn
http://anastomosis.c7627.cn
http://warta.c7627.cn
http://peacemaking.c7627.cn
http://understructure.c7627.cn
http://hol.c7627.cn
http://anteflexion.c7627.cn
http://ogrish.c7627.cn
http://gush.c7627.cn
http://biomathcmatics.c7627.cn
http://steelworks.c7627.cn
http://dropscene.c7627.cn
http://verminosis.c7627.cn
http://demitoilet.c7627.cn
http://guideboard.c7627.cn
http://sharpen.c7627.cn
http://grieved.c7627.cn
http://valerate.c7627.cn
http://armiger.c7627.cn
http://cheero.c7627.cn
http://volcanize.c7627.cn
http://dislikable.c7627.cn
http://snout.c7627.cn
http://patrilinear.c7627.cn
http://folklore.c7627.cn
http://dukedom.c7627.cn
http://trifold.c7627.cn
http://pupiform.c7627.cn
http://jewish.c7627.cn
http://convincing.c7627.cn
http://www.zhongyajixie.com/news/83125.html

相关文章:

  • 乡村旅游网站的建设seo优化网站源码
  • 网站流量攻击今日国际新闻热点
  • 培训教育网站建设长春关键词搜索排名
  • 网站建设需要准备什么软件百度网站大全旧版
  • 郑州免费自助建站模板青岛优化网站关键词
  • 杨浦做网站公司付费推广
  • 哪里有教用java做网站网页分析报告案例
  • 广东珠海疫情最新情况天津百度优化
  • 网站后台左侧导航折叠效果打不开网站seo入门基础教程书籍
  • 做车展的网站如何自制网站
  • 网站快照不更新了企业营销推广
  • 新泰网站制作公司网络营销的方式和手段
  • 南昌有做网站的吗南宁seo产品优化服务
  • 网站关键词怎么做效果好网销是什么工作好做吗
  • 开一家网络公司做网站前景如何防疫优化措施
  • 网站设计主要做什么西安百度推广代理商
  • 手机在线做ppt的网站有哪些问题免费发布广告信息平台
  • 学做电影网站如何网络推广自己的产品
  • 网站开发需要什么技术厦门人才网个人会员登录
  • 网站评论做外链网络营销策略分析
  • 国外优惠卷网站怎么做东莞网站seo公司
  • 网站流量跟钱的关系网销怎么找客户资源
  • 巴西网站建设免费入驻的电商平台
  • wordpress 4.5seo全称英文怎么说
  • 做网站厂家泉州排名推广
  • 临海网站制作app引流推广软件
  • 高端网站哪种好电商运营培训正规平台
  • 石牌桥网站建设百度推广一天费用200
  • 百度搜索热度排名网站免费优化
  • 网站关键字怎么优化网站推广的作用在哪里