Commit cdadb5ce authored by liuhy's avatar liuhy
Browse files

编写readme

parent 8cdde046
......@@ -3,6 +3,7 @@ import cv2
import numpy as np
import argparse
import os
import time
print('Runing Based On:', ort.get_device())
......@@ -50,12 +51,19 @@ def LPRNetInference(args):
if os.path.isdir(args.imgpath):
images = os.listdir(args.imgpath)
count = 0
time1 = time.perf_counter()
for image in images:
img = LPRNetPreprocess(os.path.join(args.imgpath, image))
intput = sess.get_inputs()[0].shape
preb = sess.run(None, input_feed={sess.get_inputs()[0].name: img})[0]
result = LPRNetPostprocess(preb)
if result == image[:-4]:
count += 1
print('Inference Result:', result)
time2 = time.perf_counter()
print('accuracy rate:', count / len(images))
print('average time', (time2 - time1)/count*1000)
else:
img = LPRNetPreprocess(args.imgpath)
intput = sess.get_inputs()[0].shape
......
......@@ -7,6 +7,7 @@ import numpy as np
import migraphx
import argparse
import os
import time
CHARS = ['京', '沪', '津', '渝', '冀', '晋', '蒙', '辽', '吉', '黑',
'苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘', '粤',
......@@ -56,14 +57,21 @@ def LPRNetInference(args):
if os.path.isdir(args.imgpath):
images = os.listdir(args.imgpath)
count = 0
time1 = time.perf_counter()
for image in images:
img = LPRNetPreprocess(os.path.join(args.imgpath, image))
inputName=model.get_parameter_names()[0]
inputShape=model.get_parameter_shapes()[inputName].lens()
inputName = model.get_parameter_names()[0]
inputShape = model.get_parameter_shapes()[inputName].lens()
# print("inputName:{0} \ninputShape:{1}".format(inputName,inputShape))
results = model.run({inputName: migraphx.argument(img)})
result = LPRNetPostprocess(np.array(results[0]))
if result == image[:-4]:
count += 1
print('Inference Result:', result)
time2 = time.perf_counter()
print('accuracy rate:', count / len(images))
print('average time', (time2 - time1)/count*1000)
else:
img = LPRNetPreprocess(args.imgpath)
inputName=model.get_parameter_names()[0]
......@@ -75,8 +83,8 @@ def LPRNetInference(args):
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='parameters to vaildate net')
parser.add_argument('--model', default='model/LPRNet.mxr', help='model path to inference')
parser.add_argument('--imgpath', default='imgs/川JK0707.jpg', help='the image path')
parser.add_argument('--model', default='model/LPRNet.onnx', help='model path to inference')
parser.add_argument('--imgpath', default='imgs/京PL3N67.jpg', help='the image path')
parser.add_argument('--savepath', default='model/LPRNet.mxr', help='mxr model save path and name')
args = parser.parse_args()
......
......@@ -42,9 +42,9 @@ LPRNet_migraphx_infer.py是基于Migraphx的推理脚本,使用需安装好Mig
## 性能和准确率数据
测试数据使用的是[LPRNet_Pytorch](https://github.com/sirius-ai/LPRNet_Pytorch/tree/master/data/test)
| size | personal test imgs(%) | DCU |
| :------: | :------: | :------: |
| 1.7M | 96.0+ | |
| size | personal test imgs(%) | DCU(pth/ms) |DCU(onnx/ms) | DCU(mxr/ms)|
| :------: | :------: | :------: |:------: |:------: |
| 1.7M | 96.0+ | 52 | 51 | |
## 参考
* [LPRNet: License Plate Recognition via Deep Neural Networks](https://arxiv.org/pdf/1806.10447v1.pdf)
* [LPRNet_Pytorch](https://github.com/sirius-ai/LPRNet_Pytorch)
......
No preview for this file type
......@@ -5,6 +5,7 @@ import torch
import numpy as np
from lprnet import build_lprnet
from load_data import CHARS
import time
def infer(args, image, model):
img = cv2.imread(image)
......@@ -44,15 +45,18 @@ def validation(args):
if os.path.isdir(args.imgpath):
images = os.listdir(args.imgpath)
count = 0
time1 = time.perf_counter()
for image in images:
res = infer(args, os.path.join(args.imgpath, image), model)
if res == image[:-4]:
result = infer(args, os.path.join(args.imgpath, image), model)
if result == image[:-4]:
count += 1
print('Image: ' + image + ' recongise result: '+ res)
print('acc rate:', count / len(images))
print('Image: ' + image + ' recongise result: '+ result)
time2 = time.perf_counter()
print('accuracy rate:', count / len(images))
print('average time', (time2 - time1)/count*1000)
else:
res = infer(args, args.imgpath, model)
print('Image: ' + args.imgpath + ' recongise result: '+ res)
result = infer(args, args.imgpath, model)
print('Image: ' + args.imgpath + ' recongise result: '+ result)
if args.export_onnx:
print('export pytroch model to onnx model...')
......@@ -71,8 +75,8 @@ def validation(args):
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='parameters to vaildate net')
# parser.add_argument('--model', default='model/lprnet.pth', help='model path to vaildate')
parser.add_argument('--model', default='weights/Final_LPRNet_model.pth', help='model path to vaildate')
parser.add_argument('--model', default='model/lprnet.pth', help='model path to vaildate')
# parser.add_argument('--model', default='weights/Final_LPRNet_model.pth', help='model path to vaildate')
# parser.add_argument('--imgpath', default='imgs/川JK0707.jpg', help='the image path')
parser.add_argument('--imgpath', default='/code/lpr_ori/data/test', help='the image path')
parser.add_argument('--device', default='cuda', help='Use cuda to vaildate model')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment