首页 > 分享 > ResNet 进行图片识别 (基于tf.keras)

ResNet 进行图片识别 (基于tf.keras)

最新推荐文章于 2022-09-10 10:32:32 发布

qq_20880939 于 2019-09-07 10:46:31 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

import tensorflow as tf

import matplotlib.pyplot as plt

from tensorflow.python.keras.applications.resnet50 import ResNet50

from tensorflow.python.keras.preprocessing import image

from tensorflow.python.keras.applications.resnet50 import preprocess_input, decode_predictions

inputs = tf.placeholder(tf.float32, (224, 224, 3))

tensorimg = tf.expand_dims(inputs, 0)

tensorimg =preprocess_input(tensorimg)

with tf.Session() as sess:

sess.run(tf.global_variables_initializer())

Reslayer = ResNet50(weights='imagenet')

logits = Reslayer(tensorimg)

img_path = 'hy.jpg'

img = image.load_img(img_path, target_size=(224, 224))

logitsv = sess.run(logits,feed_dict={inputs: img})

Pred =decode_predictions(logitsv, top=3)[0]

print('Predicted:', Pred,len(logitsv[0]))

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 8))

fig.sca(ax1)

ax1.imshow(img)

fig.sca(ax1)

barlist = ax2.bar(range(3), [ i[2] for i in Pred ])

barlist[0].set_color('g')

plt.sca(ax2)

plt.ylim([0, 1.1])

fig.subplots_adjust(bottom=0.2)

plt.show()

随便上网找一张图片,识别结果如下:

相关知识

基于python编程的五种鲜花识别
基于ResNet对花朵分类研究
基于深度学习和迁移学习的识花实践
基于深度学习的百合花种类识别研究
34 花卉识别
基于MSDB
基于注意力机制的小样本啤酒花病虫害识别
人工智能毕业设计基于python的花朵识别系统
深度学习基于python+TensorFlow+Django的花朵识别系统
基于深度学习的花卉识别研究

网址: ResNet 进行图片识别 (基于tf.keras) https://m.huajiangbk.com/newsview308759.html

所属分类:花卉
上一篇: 【物业动态】除草护绿,让小区花园
下一篇: 【兰州绿植公司