首页 > 分享 > 几行代码就能识别狗狗,你还在等什么?

几行代码就能识别狗狗,你还在等什么?

几行代码就能识别狗狗,你还在等什么?

M.François 于 2019-03-06 11:18:41 发布

在这里插入图片描述

来自特拉字节AI文章:https://telabytes.com/article/preview?id=20

from keras.preprocessing import image def plot_bar(predictions): types = [pred[1] for pred in predictions] probs = [pred[2] for pred in predictions] plt.barh(np.arange(len(probs)), probs) _ = plt.yticks(np.arange(len(predictions)), types) plt.show() def load_img(img_path): img = image.load_img(img_path, target_size=(224, 224)) x = image.img_to_array(img) x = np.expand_dims(x, axis=0) return x

12345678910111213141516

import matplotlib from keras.applications.inception_v3 import InceptionV3, preprocess_input, decode_predictions def predicts_inceptionV3(img_path): x = load_img(img_path) x = preprocess_input(x) # 加载InceptionV3预训练模型 # 如果本地不存在该模型,就下载 model = InceptionV3(weights='imagenet') # 预测狗狗品种 preds = model.predict(x) # 对预测的值解码,只显示前5个最大的值 predictions = decode_predictions(preds, top=5)[0] # 1.绘直方图显示 plot_bar(predictions) # 2.绘制原始图和预测概率图 # 创建一个绘图对象 fig, ax = plt.subplots() # 设置绘图的总容器大小 fig.set_size_inches(5, 5) # 取出预测的品种名称和它对应的概率值 fig_title = "".join(["{}: {:.5f}%n".format(pred[1], pred[2]*100) for pred in predictions]) # 设置在图像旁边的预测注解文字 ax.text(1.01, 0.7, fig_title, horizontalalignment='left', verticalalignment='bottom', transform=ax.transAxes) # 读取图片的数值内容 img = matplotlib.image.imread(img_path) # 在Axes对象上显示图像 ax.imshow(img)

123456789101112131415161718192021222324252627282930313233343536

输出如下图片

在这里插入图片描述
在这里插入图片描述

如果是预测这个人的了?
在这里插入图片描述

在这里插入图片描述

来自特拉字节:https://telabytes.com/article/preview?id=20

相关知识

详解pytorch实现猫狗识别98%附代码
狗狗都来矫正牙齿了!你还在等什么呢……
汪星人都整牙了,你还在等什么呢?快去
宠物文化节|萌宠强势来袭,你还在等什么?
【深度学习图像识别课程】毕业项目:狗狗种类识别(2)代码实现
宠物识别:你对狗狗们了解多少?
探秘狗狗耳朵上的代码(从犬种到健康状态)
MeowBot:ESP32 语音控制宠物猫 DIY 教程——玩转语音识别与 MQTT 智能家居控制 (附代码解析)
使用深度学习进行语音情感识别:案例演示与代码实现
扫一扫就能确认身份!你愿意给狗狗一个“芯”身份吗?

网址: 几行代码就能识别狗狗,你还在等什么? https://m.mcbbbk.com/newsview483998.html

所属分类:萌宠日常
上一篇: 口袋妖怪日月双打队伍推荐 口袋妖
下一篇: 在5G技术的加持下,运营商的智慧