diff --git a/docs/doc_whl.md b/docs/doc_whl.md index 2237891..f3c6f73 100644 --- a/docs/doc_whl.md +++ b/docs/doc_whl.md @@ -1,98 +1 @@ -## Text Detect Metric -

- - - PyPI - -SemVer2.0 - -

- - -- This library is used to calculate the three metric `Precision`, `Recall` and `H-mean` to evaluate the effect of text detection algorithms. It is used in conjunction with [Modelscope-Text Detection Test Set](https://www.modelscope.cn/datasets/liekkas/text_det_test_dataset/summary). -- Indicator calculation code reference: [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR/blob/b13f99607653c220ba94df2a8650edac086b0f37/ppocr/metrics/eval_det_iou.py) and [DB](https://github.com/MhLiao/DB/blob/3c32b808d4412680310d3d28eeb6a2d5bf1566c5/concern/icdar2015_eval/detection/iou.py#L8) - - -### 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](https://www.modelscope.cn/datasets/liekkas/text_det_test_dataset/summary), and you can use the same analogy. - - -### Usage -1. Install packages. - ```bash - pip install modelscope==1.5.2 - pip install text_det_metric - ``` -2. Run `get_pred_txt.py` to get `pred.txt` -
- Click to expand - - ```python - 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") - ``` -
-3. Run `compute_metric.py` to get the metrics on the dataset - ```python - from text_det_metric import DetectionIoUEvaluator - - metric = DetectionIoUEvaluator() - - # pred_path - pred_path = "pred.txt" - metric = metric(pred_path) - print(metric) - ``` -4. Output - ```python - { - 'precision': 0.6958333333333333, - 'recall': 0.8608247422680413, - 'hmean': 0.7695852534562212, - 'avg_elapse': 2.0107483345529307 - } - ``` - ### See details for [TextDetMetric](https://github.com/SWHL/TextDetMetric).