{"id":16881473,"url":"https://github.com/swhl/tablerecognitionmetric","last_synced_at":"2025-03-22T07:32:13.967Z","repository":{"id":180605009,"uuid":"664899008","full_name":"SWHL/TableRecognitionMetric","owner":"SWHL","description":"Compute benchmark of table structure recognition.","archived":false,"fork":false,"pushed_at":"2024-04-23T14:01:34.000Z","size":50,"stargazers_count":18,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T09:37:39.365Z","etag":null,"topics":["ocr","s-teds","table-recognition","teds"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SWHL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-11T02:18:11.000Z","updated_at":"2025-02-05T01:12:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"c207cab2-cfcb-4918-a715-091d68e976b0","html_url":"https://github.com/SWHL/TableRecognitionMetric","commit_stats":{"total_commits":22,"total_committers":1,"mean_commits":22.0,"dds":0.0,"last_synced_commit":"7c8292fc6222c7280b936f39ba849df888842615"},"previous_names":["swhl/tablerecognitionmetric"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTableRecognitionMetric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTableRecognitionMetric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTableRecognitionMetric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SWHL%2FTableRecognitionMetric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SWHL","download_url":"https://codeload.github.com/SWHL/TableRecognitionMetric/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244925175,"owners_count":20532873,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ocr","s-teds","table-recognition","teds"],"created_at":"2024-10-13T16:02:43.407Z","updated_at":"2025-03-22T07:32:13.288Z","avatar_url":"https://github.com/SWHL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cdiv align=\"center\"\u003e\n    \u003ch1\u003e\u003cb\u003eTable Recognition Metric\u003c/b\u003e\u003c/h1\u003e\n  \u003c/div\u003e\n\n\u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/python-\u003e=3.6,\u003c3.12-aff.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/table_recognition_metric/\"\u003e\u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/table_recognition_metric\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pepy.tech/project/table-recognition-metric\"\u003e\u003cimg src=\"https://static.pepy.tech/personalized-badge/table-recognition-metric?period=total\u0026units=abbreviation\u0026left_color=grey\u0026right_color=blue\u0026left_text=Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://semver.org/\"\u003e\u003cimg alt=\"SemVer2.0\" src=\"https://img.shields.io/badge/SemVer-2.0-brightgreen\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/psf/black\"\u003e\u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"\u003e\u003c/a\u003e\n\n\u003c/div\u003e\n\n\n### 简介\n该库用于计算TEDS指标，用来评测表格识别算法效果。可与[table_rec_test_dataset](https://huggingface.co/datasets/SWHL/table_rec_test_dataset)配套使用。\n\nTEDS计算代码参考：[PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/ppstructure/table/table_metric/table_metric.py) 和 [DAVAR-Lab-OCR](https://github.com/hikopensource/DAVAR-Lab-OCR/blob/main/davarocr/davar_table/utils/metric.py)\n\n### 安装\n```bash\npip install table_recognition_metric\n```\n\n### 使用说明：\n#### 命令行运行\n- Usage:\n    ```bash\n    $ table_recognition_metric -h\n    usage: table_recognition_metric [-h] [-steds] [-gt GT_HTML] [-pred PRED_HTML]\n\n    options:\n    -h, --help            show this help message and exit\n    -steds, --structure_only\n    -gt GT_HTML, --gt_html GT_HTML\n    -pred PRED_HTML, --pred_html PRED_HTML\n    ```\n- Example:\n    ```bash\n    $ table_recognition_metric -gt '\u003chtml\u003e\u003cbody\u003e\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e购买方\u003c/td\u003e\u003ctd colspan=\"5\"\u003e纳税人识别号地址、电记开户行及账号\u003c/td\u003e\u003ctd\u003e密码区\u003c/td\u003e\u003ctd colspan=\"4\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\"2\"\u003e货物或应税劳务、服务名称理肤泉清痘旅行装控油祛痘调节水油平衡理肤泉特安舒缓修护乳40ml合计\u003c/td\u003e\u003ctd\u003e规格型号\u003c/td\u003e\u003ctd\u003e单位\u003c/td\u003e\u003ctd\u003e11\u003c/td\u003e\u003ctd colspan=\"3\"\u003e\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e税率17%17%\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\"2\"\u003e价税合计（大写）\u003c/td\u003e\u003ctd colspan=\"9\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e销售方\u003c/td\u003e\u003ctd colspan=\"5\"\u003e纳税人识别号地址、电话开户行及账号\u003c/td\u003e\u003ctd\u003e备注\u003c/td\u003e\u003ctd colspan=\"4\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/body\u003e\u003c/html\u003e' -pred ''\n\n    # 0.0\n    ```\n#### 脚本运行\n\u003e [!NOTE]\n\u003e 如果只需要计算Struct-TEDS，只需在声明TEDS实例时，传入参数`structure_only=True`即可，默认该参数为`False`，即计算TEDS. e.g.\n\u003e\n\u003e `teds = TEDS(structure_only=True)`\n\n```python\nfrom table_recognition_metric import TEDS\n\nteds = TEDS()\n\ngt_html = '\u003chtml\u003e\u003cbody\u003e\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e购买方\u003c/td\u003e\u003ctd colspan=\"5\"\u003e纳税人识别号地址、电记开户行及账号\u003c/td\u003e\u003ctd\u003e密码区\u003c/td\u003e\u003ctd colspan=\"4\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\"2\"\u003e货物或应税劳务、服务名称理肤泉清痘旅行装控油祛痘调节水油平衡理肤泉特安舒缓修护乳40ml合计\u003c/td\u003e\u003ctd\u003e规格型号\u003c/td\u003e\u003ctd\u003e单位\u003c/td\u003e\u003ctd\u003e11\u003c/td\u003e\u003ctd colspan=\"3\"\u003e\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e税率17%17%\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\"2\"\u003e价税合计（大写）\u003c/td\u003e\u003ctd colspan=\"9\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e销售方\u003c/td\u003e\u003ctd colspan=\"5\"\u003e纳税人识别号地址、电话开户行及账号\u003c/td\u003e\u003ctd\u003e备注\u003c/td\u003e\u003ctd colspan=\"4\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/body\u003e\u003c/html\u003e'\npred_html = '\u003chtml\u003e\u003cbody\u003e\u003ctable\u003e\u003ctr\u003e\u003ctd\u003e购买方\u003c/td\u003e\u003ctd colspan=\"5\"\u003e纳税人识别号地址、电记开户行及账号\u003c/td\u003e\u003ctd\u003e密码区\u003c/td\u003e\u003ctd colspan=\"4\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\"2\"\u003e货物或应税劳务、服务名称理肤泉清痘旅行装控油祛痘调节水油平衡理肤泉特安舒缓修护乳40ml合计\u003c/td\u003e\u003ctd\u003e规格型号\u003c/td\u003e\u003ctd\u003e单位\u003c/td\u003e\u003ctd\u003e11\u003c/td\u003e\u003ctd colspan=\"3\"\u003e\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e税率17%17%\u003c/td\u003e\u003ctd\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\"2\"\u003e价税合计（大写）\u003c/td\u003e\u003ctd colspan=\"9\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e销售方\u003c/td\u003e\u003ctd colspan=\"5\"\u003e纳税人识别号地址、电话开户行及账号\u003c/td\u003e\u003ctd\u003e备注\u003c/td\u003e\u003ctd colspan=\"4\"\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\u003c/body\u003e\u003c/html\u003e'\n\nscore = teds(gt_html, pred_html)\nprint(score)\n# 1.0\n```\n\n#### 数据集上评测\n- 这里以[`rapid-table`](https://github.com/RapidAI/RapidStructure/blob/main/docs/README_Table.md)在表格数据集[table_rec_test_dataset](https://huggingface.co/datasets/SWHL/table_rec_test_dataset)上的评测代码，大家可以以此类推。\n- 安装必要的包\n    ```bash\n    pip install datasets\n    pip install rapid_table\n    pip install rapidocr_onnxruntime\n    pip install table_recognition_metric\n    ```\n- 运行测试\n    ```python\n    import numpy as np\n    from datasets import load_dataset\n    from rapid_table import RapidTable\n    from tqdm import tqdm\n\n    from table_recognition_metric import TEDS\n\n    dataset = load_dataset(\"SWHL/table_rec_test_dataset\")\n    test_data = dataset[\"test\"]\n\n    table_engine = RapidTable()\n    teds = TEDS(structure_only=True)\n\n    content = []\n    for one_data in tqdm(test_data):\n        img = one_data.get(\"image\")\n        gt = one_data.get(\"html\")\n\n        pred_str, _, _ = table_engine(np.array(img))\n\n        scores = teds(gt, pred_str)\n        content.append(scores)\n\n    avg = sum(content) / len(content)\n    print(f\"TEDS: {avg:.5f}\")\n\n    ```\n\n### Tree-EditDistance-based Similarity (TEDS)\n- TEDS是IBM在论文《[Image-based table recognition: data, model, and evaluation](https://arxiv.org/pdf/1911.10683)》中提出的。\n- [之前提出的评测算法](https://ieeexplore.ieee.org/document/1227792)，主要是将一个表格的`ground truth`和`recognition result`各自展平为非空cell两两之间的邻接关系列表。然后通过比较这两个列表，来计算precision, recall和F1-score。该metric主要存在两个明显问题：\n    1. 由于它只检查非空单元格之间的直接邻接关系，因此它无法检测由空单元格和超出直接邻居的单元格未对齐引起的错误；\n    2. 由于它通过精准匹配来检查关系，因此它没有衡量fine-grained单元格内容识别性能的机制。\n- 针对以上问题，TEDS通过以下方法予以解决：\n    1. 通过在全局树结构级别检查识别结果，使其能够识别它识别所有类型的结构错误，来解决上述问题1；\n    2. 当**tree-edit**的操作是节点替换时，计算对应的字符串编辑距离，来解决上述问题2。\n- 计算公式：\n\n   $$TEDS(T_{a}, T_{b}) = 1 - \\frac{EditDist(T_{a}, T_{b})}{max(|T_{a}|, |T_{b}|)}$$\n\n    其中， $EditDist$指的是**tree-edit distance**, $|T|$ 指的是在 $T$ 中节点的数量。一个表格还原算法在一系列测试集上识别效果可以定义为：测试集中所有样例逐个计算其**ground truth**和**predict result**之间的TEDS，最终对所有样例的TEDS求均值得到最终得分。\n\n### 更新日志\n#### 2023-12-27 v0.0.4 update:\n- 显示添加计算S-TEDS指标参数","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswhl%2Ftablerecognitionmetric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswhl%2Ftablerecognitionmetric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswhl%2Ftablerecognitionmetric/lists"}