Tool of computing the metric of text detection
Project description
Text Detect Metric
- This library is used to calculate the three metric
Precision
,Recall
andH-mean
to evaluate the effect of text detection algorithms. It is used in conjunction with Modelscope-Text Detection Test Set. - Indicator calculation code reference: PaddleOCR and DB
Evaluate on the custom dataset.
- Here we use the evaluation code of
ch_ppocr_v3_det
on the text detection test set liekkas/text_det_test_dataset, and you can use the same analogy.
Usage
-
Install packages.
pip install modelscope==1.5.2 pip install text_det_metric
-
Run
get_pred_txt.py
to getpred.txt
Click to expand
from pathlib import Path import cv2 import yaml from modelscope.msdatasets import MsDataset from tqdm import tqdm from det_demos.ch_ppocr_v3_det import TextDetector root_dir = Path(__file__).resolve().parent def read_yaml(yaml_path): with open(yaml_path, "rb") as f: data = yaml.load(f, Loader=yaml.Loader) return data test_data = MsDataset.load( "text_det_test_dataset", namespace="liekkas", subset_name="default", split="test", ) config_path = root_dir / 'det_demos' / 'ch_ppocr_v3_det' / 'config.yaml' config = read_yaml(str(config_path)) # Configure the onnx model path. config['model_path'] = str(root_dir / 'det_demos' / config['model_path']) text_detector = TextDetector(config) content = [] for one_data in tqdm(test_data): img_path = one_data.get("image:FILE") img = cv2.imread(str(img_path)) dt_boxes, elapse = text_detector(img) content.append(f"{img_path}\t{dt_boxes.tolist()}\t{elapse}") with open("pred.txt", "w", encoding="utf-8") as f: for v in content: f.write(f"{v}\n")
-
Run
compute_metric.py
to get the metrics on the datasetfrom text_det_metric import DetectionIoUEvaluator metric = DetectionIoUEvaluator() # pred_path pred_path = "pred.txt" metric = metric(pred_path) print(metric)
-
Output
{ 'precision': 0.6958333333333333, 'recall': 0.8608247422680413, 'hmean': 0.7695852534562212, 'avg_elapse': 2.0107483345529307 }
See details for TextDetMetric.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for text_det_metric-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b222536244305d987357d448ce9d823684d8df76168f5ffe9037e84042486a80 |
|
MD5 | 32d35dbcb7514dadb00c84ee1b1bbb49 |
|
BLAKE2b-256 | e5aff0f4cf99e6b6afa83db0bb431b60fdb281ba18f6015e46b99af4f183baa9 |