FLming / CRNN.tf2

Convolutional Recurrent Neural Network(CRNN) for End-to-End Text Recognition - TensorFlow 2
MIT License
152 stars 56 forks source link

Prediction accuracy in ONNX Runtime #21

Closed mlaszko closed 3 years ago

mlaszko commented 3 years ago

I converted model trained in CRNN.tf2 to onnx format(tensorflow-onnx). Thanks to @FLming I know that it is impossible to run it in OpenCV so I tried ONNX Runtime. It works, but I don't know how to get prediction accuracy?

import onnxruntime as rt
from onnxruntime.datasets import get_example
import cv2
import numpy as np

img = cv2.imread("file.jpg")
img = img.astype(np.float32)

model = get_example("model.onnx")
sess = rt.InferenceSession(model, providers=["CPUExecutionProvider"])
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name
result = sess.run([output_name], {input_name: img})
FLming commented 3 years ago

The model outputs the character probability(after softmax), You can refer to the calculation methods in the repo to get prediction accuracy. or you can decode outputs first then determine whether the strings are equal to get prediction accuracy.