28 lines
845 B
Python
28 lines
845 B
Python
import os
|
|
from paddleocr import PaddleOCR
|
|
from typing import Optional
|
|
|
|
ocr = PaddleOCR(rec_model_dir="output/vin_rec_inference")
|
|
|
|
def get_best_accuracy(ocr: PaddleOCR, file_path: str) -> Optional[tuple[str, float]]:
|
|
result = ocr.predict(file_path)
|
|
texts_with_scores = [item for item in filter(
|
|
lambda x: len(x[0]) == 17,
|
|
zip(result[0]["rec_texts"], result[0]["rec_scores"])
|
|
)]
|
|
if texts_with_scores:
|
|
return max(
|
|
texts_with_scores,
|
|
key=lambda y: y[1]
|
|
)
|
|
else:
|
|
return None
|
|
|
|
|
|
with open("train_data/val.txt", "r") as label_file:
|
|
for line in label_file.readlines():
|
|
file_name, label = line.split("\t")
|
|
path = os.path.join("train_data", os.path.join("images", file_name))
|
|
print(file_name)
|
|
print(get_best_accuracy(ocr, path))
|