Downloads · 30 days
9
13% of all-time downloads
protonx-models/protonx-table-detector
protonx-table-detector is a machine learning model from protonx-models. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Downloads · 30 days
9
13% of all-time downloads
All-time downloads
68
Public
Repo size
9.2 MB
Likes
6
Public
Click a slice to open those files.
.pth9.2 MB · 100%
From the Hugging Face model README
This model helps ProtonX support customers in reducing OCR processing costs. For documents that do not contain tables, ProtonX routes them to open-source OCR models such as Dots OCR or DeepSeek OCR. For documents with complex tables, ProtonX routes them to more powerful OCR models such as Gemini OCR, ensuring high accuracy where it matters most.
This model is a binary image classification model designed to determine whether an input document image contains at least one table.

Built on MobileNetV2 architecture, the model is optimized for document images and scanned PDFs, especially Vietnamese documents, and is intended to be used as a fast pre-filtering step in OCR and document understanding pipelines.
Task: Binary image classification
Objective: Detect table presence in an image
| ID | Label | Meaning |
|---|---|---|
| 0 | no_table | Image contains no tables |
| 1 | table | Image contains one or more tables |
⚠️ The model detects presence, not the number or location of tables.
The model is trained using a combination of:
This combination improves generalization across both clean and noisy document images.
import torch
import torch.nn as nn
import torchvision
from torchvision import transforms
from torchvision import models as pretrained_models
from PIL import Image
from huggingface_hub import hf_hub_download
class TableDetector:
def __init__(self, model_name: str, device: str = 'cpu'):
self.device = torch.device(device)
self.model_path = hf_hub_download(repo_id=model_name, filename="model/table_detector.pth")
self.model = self.load_model(self.model_path)
self.model.to(self.device)
self.model.eval()
def load_model(self, model_path: str):
model = pretrained_models.mobilenet_v2(weights=None)
model.classifier[1] = nn.Linear(in_features=model.classifier[1].in_features, out_features=2)
model.load_state_dict(torch.load(model_path, map_location=self.device))
return model
def preprocess_image(self, image_path: str):
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
])
image = Image.open(image_path).convert('RGB')
image = transform(image).unsqueeze(0) # Add batch dimension
return image.to(self.device)
def predict(self, image_path: str):
image = self.preprocess_image(image_path)
with torch.no_grad():
outputs = self.model(image)
_, preds = torch.max(outputs, 1)
return 'have_table' if preds.item() == 1 else 'no_table'
if __name__ == "__main__":
model = TableDetector(model_name='protonx-models/table-detector', device='cpu')
prediction = model.predict("images/document_page_01.png")
print(prediction)
from protonx import ProtonX
client = ProtonX(
mode="offline"
)
prediction = client.ocr.detect_table(image_path="images/document_page_01.png")
print(prediction)
Thanks to: