Skip to main content

Trích xuất bảng từ ảnh thành Markdown cho RAG pipeline

Project description

RagTable

Extract tables from images/PDFs to Markdown — fast, accurate, RAG-ready

RagTable converts table images into structured Markdown using a segmentation model and per-cell OCR. Built for borderless and complex tables (academic papers, reports, scanned documents), with output that plugs directly into RAG pipelines or LLM contexts.


Features

  • Table structure segmentation via EfficientUNet (~19M params) — detects row, col, col_header, row_header, and span masks
  • Span detection — merged cells are identified and rendered correctly in Markdown
  • Per-cell OCR via PaddleOCR — each cell is cropped and read individually to minimize noise
  • Smart header handling — header rows get a dedicated OCR pass with spatial mapping for better accuracy
  • Automatic post-processing — removes phantom edge columns, empty rows, and footer artifacts
  • Fully offline — no external API calls, suitable for sensitive or air-gapped environments
  • Multi-format input: PNG, JPG, TIFF

Installation

CPU (default)

pip install ragtab

This installs everything needed: PyTorch, PaddleOCR, PaddlePaddle (CPU), and other dependencies.

GPU (NVIDIA CUDA)

pip install ragtab[gpu]

This replaces paddlepaddle (CPU) with paddlepaddle-gpu for ~3-5× faster OCR inference on NVIDIA GPUs.

Requirements: Python ≥ 3.10

Install from source

git clone https://github.com/tai03102004/rag-table
cd ragtab
pip install -e .

Quickstart

from ragtab.pipeline import extract_table

markdown, cells = extract_table(
    "table.png",
    model_path="checkpoints/unet_best.pt",
    ocr_engine="paddleocr"
)

print(markdown)

Output:

| Item        | Price | Qty |
| ----------- | ----- | --- |
| iPhone 15   | 999   | 12  |
| Samsung S24 | 899   | 8   |

How It Works

Input image (resized to 384×384)
       │
       ▼
[1] EfficientUNet → 5 segmentation masks
       │
       ▼
[2] Projection analysis → row/column separator positions
       │
       ▼
[3] Span detection → connected components on span mask
       │
       ▼
[4] Grid construction → per-cell bounding boxes
       │
       ▼
[5] OCR — header rows: spatial mapping pass
        — body cells: per-cell crop + PaddleOCR
       │
       ▼
[6] Post-processing → drop phantom columns, empty rows, footers
       │
       ▼
[7] Markdown export

Each stage is independently accessible so you can customize or swap components.


Custom checkpoint

If you've trained your own model or want to use a different checkpoint:

markdown, cells = extract_table("table.png", model_path="path/to/your_model.pt")

Manual download (optional)


Cache location

By default, the model is cached at ~/.cache/ragtab/. Override via environment variable:

export RAGTAB_CACHE_DIR=/path/to/custom/cache

Project Structure

RagTable/
├── python/
│   └── ragtab/
│       ├── __init__.py
│       ├── detection.py     # Mask → grid cells
│       ├── model.py         # EfficientUNet definition
│       ├── ocr.py           # PaddleOCR wrapper + text cleaning
│       ├── pipeline.py      # End-to-end extract_table()
│       └── utils.py
├── checkpoints/
├── notebooks/
│   └── 02_table-recognition.ipynb
└── README.md

License

MIT — free to use, including for commercial purposes.


Author

Dinh Duc Taidinhductai2004@gmail.com

If you find this useful, consider giving it a ⭐️ on GitHub!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ragtab-0.1.4.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ragtab-0.1.4-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file ragtab-0.1.4.tar.gz.

File metadata

  • Download URL: ragtab-0.1.4.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for ragtab-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4311295c166fee767e80bab34ff8331ecd3e573b46b7c9b364c322b2cf402d17
MD5 76046a98dc19d27780fe28f12afee759
BLAKE2b-256 2076947482a33f5f08aea40ca1de8f7551a0050c187bddca366ff4ce7815f281

See more details on using hashes here.

File details

Details for the file ragtab-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ragtab-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for ragtab-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1459312986e7ef138930da9d44a665e23921f4a52e297a4fa0e8f28028b48b8c
MD5 b690101d3ba1dc05d1eb63dda4875589
BLAKE2b-256 f4bea01f83346ee9b681b17c8a0689b9f4748ba3bb54e08b6755110963c14f72

See more details on using hashes here.

Supported by

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