Добавил скрипты для валидации.
This commit is contained in:
27
scripts/score_validation.py
Normal file
27
scripts/score_validation.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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))
|
||||
Reference in New Issue
Block a user