Skip to main content

Tool of computing the metric of text detection

Project description

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.
  • 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

  1. Install packages.

    pip install modelscope==1.5.2
    pip install text_det_metric
    
  2. Run get_pred_txt.py to get pred.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")
    
  3. Run compute_metric.py to get the metrics on the dataset

    from text_det_metric import DetectionIoUEvaluator
    
    metric = DetectionIoUEvaluator()
    
    # pred_path
    pred_path = "pred.txt"
    metric = metric(pred_path)
    print(metric)
    
  4. 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

text_det_metric-0.0.7-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page