1 Star 0 Fork 1

liulan123/traffic_sign_classfication

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
predict.py 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
Your Name 提交于 2018-04-09 16:45 +08:00 . init commit
#导包
import argparse
import cv2
import numpy as np
import imutils
from keras.models import load_model
from keras.preprocessing.image import img_to_array
NORM_SIZE = 32
def args_parse():
ap = argparse.ArgumentParser()
ap.add_argument("-m", "--model", required=True, help="path to trained model model")
ap.add_argument("-i", "--image", required=True, help="path to input image")
ap.add_argument("-s", "--show", required=True, action="store_true", help="show predict image", default=False)
args = vars(ap.parse_args())
return args
def predict(args):
print("loading model...")
model = load_model(args['model'])
print("loading image...")
image = cv2.imread(args['image'])
orig = image.copy()
#预处理
image = cv2.resize(image,(NORM_SIZE, NORM_SIZE))
image = image.astype("float") / 255.0
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
#预测
result = model.predict(image)[0]
proba = np.max(result)
label = str(np.where(result==proba)[0])
label = "{}: {:.2f}%".format(label, proba*100)
print(label)
if args['show']:
output = imutils.resize(orig, width=400)
cv2.putText(output, label, (10, 25), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
cv2.imshow("Output", output)
cv2.waitKey(0)
if __name__=="__main__":
args = args_parse()
predict(args)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/ll202324/traffic_sign_classfication.git
git@gitee.com:ll202324/traffic_sign_classfication.git
ll202324
traffic_sign_classfication
traffic_sign_classfication
master

搜索帮助