CoolFace
Modelpublic

docling-project/DocumentFigureClassifier-v2.5

sourceHugging Facemitupdated 6mo agoView on Hugging Face
3likes77kdownloads
Model Card

EfficientNet-B0 Document Figure Classifier v2.5

This is an image classification model based on Google EfficientNet-B0, fine-tuned on a subset of the subset of HuggingFace/finepdfs to classify document figures into one of the following 26 categories:

  1. 1.logo
  2. 2.photograph
  3. 3.icon
  4. 4.engineering_drawing
  5. 5.line_chart
  6. 6.bar_chart
  7. 7.other
  8. 8.table
  9. 9.flow_chart
  10. 10.screenshot_from_computer
  11. 11.signature
  12. 12.screenshot_from_manual
  13. 13.geographical_map
  14. 14.pie_chart
  15. 15.page_thumbnail
  16. 16.stamp
  17. 17.music
  18. 18.calendar
  19. 19.qr_code
  20. 20.bar_code
  21. 21.full_page_image
  22. 22.scatter_plot
  23. 23.chemistry_structure
  24. 24.topographical_map
  25. 25.crossword_puzzle
  26. 26.box_plot

Model Performance

Note: This model uses the same architecture and implementation as v2.0. The improved performance is achieved by training on a dataset that is 10 times larger than the one used for v2.0.

The model was evaluated on a held-out test set from the finepdfs dataset with the following metrics:

Metricv2.5v2.0Improvement
Accuracy0.907030.87053+3.65%
Balanced Accuracy0.688360.60231+8.61%
Macro F10.689420.60144+8.80%
Weighted F10.907160.87270+3.45%
Cohen's Kappa0.874490.82563+4.89%

Per-Label Performance

LabelPrecision (v2.5)Recall (v2.5)Precision (v2.0)Recall (v2.0)
logo0.928070.918160.883170.88728
photograph0.909660.960290.881690.93359
icon0.836050.826780.792810.72133
engineering_drawing0.716890.811720.587950.71555
line_chart0.730550.921170.758650.84576
bar_chart0.885990.927200.726240.93883
other0.418930.382130.282390.37312
table0.986360.967650.979500.95250
flow_chart0.759260.824250.615270.81518
screenshot_from_computer0.859520.719800.805100.65844
signature0.890200.859710.918520.80914
screenshot_from_manual0.485590.345430.347480.20662
geographical_map0.867800.852190.829590.80720
pie_chart0.968800.942200.899030.93931
page_thumbnail0.520080.351880.401940.21475
stamp0.712690.417940.634920.26258
music0.480370.577780.769550.51944
calendar0.528800.287750.511760.24786
qr_code0.956940.932400.975000.90909
bar_code0.342440.843050.120870.82063
full_page_image0.403230.657890.437500.28116
scatter_plot0.668480.672130.603860.68306
chemistry_structure0.727810.654260.774440.54787
topographical_map0.833330.384620.687500.28205
crossword_puzzle0.571430.216220.800000.21622
box_plot0.857140.642861.000000.07143

How to use - Transformers

Example of how to classify an image into one of the 26 classes using transformers:

python
import torch
import torchvision.transforms as transforms

from transformers import EfficientNetForImageClassification
from PIL import Image
import requests


urls = [
    'http://images.cocodataset.org/val2017/000000039769.jpg',
    'http://images.cocodataset.org/test-stuff2017/000000001750.jpg',
    'http://images.cocodataset.org/test-stuff2017/000000000001.jpg'
]

image_processor = transforms.Compose(
    [
        transforms.Resize((224, 224)),
        transforms.ToTensor(),
        transforms.Normalize(
            mean=[0.485, 0.456, 0.406],
            std=[0.47853944, 0.4732864, 0.47434163],
        ),
    ]
)

images = []
for url in urls:
    image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
    image = image_processor(image)
    images.append(image)


model_id = 'docling-project/DocumentFigureClassifier-v2.5'

model = EfficientNetForImageClassification.from_pretrained(model_id)

labels = model.config.id2label

device = torch.device("cpu")

torch_images = torch.stack(images).to(device)

with torch.no_grad():
    logits = model(torch_images).logits  # (batch_size, num_classes)
    probs_batch = logits.softmax(dim=1)  # (batch_size, num_classes)
    probs_batch = probs_batch.cpu().numpy().tolist()

for idx, probs_image in enumerate(probs_batch):
    preds = [(labels[i], prob) for i, prob in enumerate(probs_image)]
    preds.sort(key=lambda t: t[1], reverse=True)
    print(f"{idx}: {preds}")

How to use - ONNX

Example of how to classify an image into one of the 26 classes using onnx runtime:

python
import onnxruntime

import numpy as np
import torchvision.transforms as transforms

from PIL import Image
import requests

LABELS = [
    "logo",
    "photograph",
    "icon",
    "engineering_drawing",
    "line_chart",
    "bar_chart",
    "other",
    "table",
    "flow_chart",
    "screenshot_from_computer",
    "signature",
    "screenshot_from_manual",
    "geographical_map",
    "pie_chart",
    "page_thumbnail",
    "stamp",
    "music",
    "calendar",
    "qr_code",
    "bar_code",
    "full_page_image",
    "scatter_plot",
    "chemistry_structure",
    "topographical_map",
    "crossword_puzzle",
    "box_plot"
]


urls = [
    'http://images.cocodataset.org/val2017/000000039769.jpg',
    'http://images.cocodataset.org/test-stuff2017/000000001750.jpg',
    'http://images.cocodataset.org/test-stuff2017/000000000001.jpg'
]

images = []
for url in urls:
    image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
    images.append(image)


image_processor = transforms.Compose(
    [
        transforms.Resize((224, 224)),
        transforms.ToTensor(),
        transforms.Normalize(
            mean=[0.485, 0.456, 0.406],
            std=[0.47853944, 0.4732864, 0.47434163],
        ),
    ]
)


processed_images_onnx = [image_processor(image).unsqueeze(0) for image in images]

# onnx needs numpy as input
onnx_inputs = [item.numpy(force=True) for item in processed_images_onnx]

# pack into a batch
onnx_inputs = np.concatenate(onnx_inputs, axis=0)

ort_session = onnxruntime.InferenceSession(
    "./DocumentFigureClassifier-v2_5-onnx/model.onnx",
    providers=["CUDAExecutionProvider", "CPUExecutionProvider"]
)


for item in ort_session.run(None, {'input': onnx_inputs}):
    for x in iter(item):
        pred = x.argmax()
        print(LABELS[pred])

Training Data

This model was trained on a subset of the subset of HuggingFace/finepdfs, a large-scale dataset for document understanding tasks.

Citation

If you use this model in your work, please cite the following papers:

@article{Tan2019EfficientNetRM,
  title={EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks},
  author={Mingxing Tan and Quoc V. Le},
  journal={ArXiv},
  year={2019},
  volume={abs/1905.11946}
}

@techreport{Docling,
  author = {Deep Search Team},
  month = {8},
  title = {{Docling Technical Report}},
  url={https://arxiv.org/abs/2408.09869},
  eprint={2408.09869},
  doi = "10.48550/arXiv.2408.09869",
  version = {1.0.0},
  year = {2024}
}