tensorflow2.0加载自己的模型预测图片

import tensorflow as tf
import numpy as np
from tensorflow.keras.preprocessing import image
model=tf.keras.models.load_model("./rubbish.h5")
img_path="./u.jpg"
img = image.load_img(img_path, target_size=(512, 512))
img = image.img_to_array(img)
img = np.expand_dims(img, axis=0)
pred_class = model.predict(img)
max_index = np.argmax(pred_class, axis=-1)
acc=pred_class[0][int(max_index)]*100
rubbish_list=['U盘', '伞', '卫生纸', '圆规', '尺子', '布娃娃', '废纸', '手机', '手机充电器', '手表', '梳子', '橡皮', '毛巾', '水杯', '牙刷', '矿泉水瓶', '笔记本', '签字笔', '自行车', '订书机', '钥匙', '鼠标']
print("结果为{}的准确率是{:.2f}%".format(rubbish_list[int(max_index)],acc))

在这里插入图片描述

发布了60 篇原创文章 · 获赞 15 · 访问量 4052

猜你喜欢

转载自blog.csdn.net/qq_15557299/article/details/104321309