Views
No views yet
| Metric | v2.5 | v2.0 | Improvement |
|---|---|---|---|
| Accuracy | 0.90703 | 0.87053 | +3.65% |
| Balanced Accuracy | 0.68836 | 0.60231 | +8.61% |
| Macro F1 | 0.68942 | 0.60144 | +8.80% |
| Weighted F1 | 0.90716 | 0.87270 | +3.45% |
| Cohen's Kappa | 0.87449 | 0.82563 | +4.89% |
| Label | Precision (v2.5) | Recall (v2.5) | Precision (v2.0) | Recall (v2.0) |
|---|---|---|---|---|
| logo | 0.92807 | 0.91816 | 0.88317 | 0.88728 |
| photograph | 0.90966 | 0.96029 | 0.88169 | 0.93359 |
| icon | 0.83605 | 0.82678 | 0.79281 | 0.72133 |
| engineering_drawing | 0.71689 | 0.81172 | 0.58795 | 0.71555 |
| line_chart | 0.73055 | 0.92117 | 0.75865 | 0.84576 |
| bar_chart | 0.88599 | 0.92720 | 0.72624 | 0.93883 |
| other | 0.41893 | 0.38213 | 0.28239 | 0.37312 |
| table | 0.98636 | 0.96765 | 0.97950 | 0.95250 |
| flow_chart | 0.75926 | 0.82425 | 0.61527 | 0.81518 |
| screenshot_from_computer | 0.85952 | 0.71980 | 0.80510 | 0.65844 |
| signature | 0.89020 | 0.85971 | 0.91852 | 0.80914 |
| screenshot_from_manual | 0.48559 | 0.34543 | 0.34748 | 0.20662 |
| geographical_map | 0.86780 | 0.85219 | 0.82959 | 0.80720 |
| pie_chart | 0.96880 | 0.94220 | 0.89903 | 0.93931 |
| page_thumbnail | 0.52008 | 0.35188 | 0.40194 | 0.21475 |
| stamp | 0.71269 | 0.41794 | 0.63492 | 0.26258 |
| music | 0.48037 | 0.57778 | 0.76955 | 0.51944 |
| calendar | 0.52880 | 0.28775 | 0.51176 | 0.24786 |
| qr_code | 0.95694 | 0.93240 | 0.97500 | 0.90909 |
| bar_code | 0.34244 | 0.84305 | 0.12087 | 0.82063 |
| full_page_image | 0.40323 | 0.65789 | 0.43750 | 0.28116 |
| scatter_plot | 0.66848 | 0.67213 | 0.60386 | 0.68306 |
| chemistry_structure | 0.72781 | 0.65426 | 0.77444 | 0.54787 |
| topographical_map | 0.83333 | 0.38462 | 0.68750 | 0.28205 |
| crossword_puzzle | 0.57143 | 0.21622 | 0.80000 | 0.21622 |
| box_plot | 0.85714 | 0.64286 | 1.00000 | 0.07143 |
1import torch
2import torchvision.transforms as transforms
3
4from transformers import EfficientNetForImageClassification
5from PIL import Image
6import requests
7
8
9urls = [
10 'http://images.cocodataset.org/val2017/000000039769.jpg',
11 'http://images.cocodataset.org/test-stuff2017/000000001750.jpg',
12 'http://images.cocodataset.org/test-stuff2017/000000000001.jpg'
13]
14
15image_processor = transforms.Compose(
16 [
17 transforms.Resize((224, 224)),
18 transforms.ToTensor(),
19 transforms.Normalize(
20 mean=[0.485, 0.456, 0.406],
21 std=[0.47853944, 0.4732864, 0.47434163],
22 ),
23 ]
24)
25
26images = []
27for url in urls:
28 image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
29 image = image_processor(image)
30 images.append(image)
31
32
33model_id = 'docling-project/DocumentFigureClassifier-v2.5'
34
35model = EfficientNetForImageClassification.from_pretrained(model_id)
36
37labels = model.config.id2label
38
39device = torch.device("cpu")
40
41torch_images = torch.stack(images).to(device)
42
43with torch.no_grad():
44 logits = model(torch_images).logits # (batch_size, num_classes)
45 probs_batch = logits.softmax(dim=1) # (batch_size, num_classes)
46 probs_batch = probs_batch.cpu().numpy().tolist()
47
48for idx, probs_image in enumerate(probs_batch):
49 preds = [(labels[i], prob) for i, prob in enumerate(probs_image)]
50 preds.sort(key=lambda t: t[1], reverse=True)
51 print(f"{idx}: {preds}")1import onnxruntime
2
3import numpy as np
4import torchvision.transforms as transforms
5
6from PIL import Image
7import requests
8
9LABELS = [
10 "logo",
11 "photograph",
12 "icon",
13 "engineering_drawing",
14 "line_chart",
15 "bar_chart",
16 "other",
17 "table",
18 "flow_chart",
19 "screenshot_from_computer",
20 "signature",
21 "screenshot_from_manual",
22 "geographical_map",
23 "pie_chart",
24 "page_thumbnail",
25 "stamp",
26 "music",
27 "calendar",
28 "qr_code",
29 "bar_code",
30 "full_page_image",
31 "scatter_plot",
32 "chemistry_structure",
33 "topographical_map",
34 "crossword_puzzle",
35 "box_plot"
36]
37
38
39urls = [
40 'http://images.cocodataset.org/val2017/000000039769.jpg',
41 'http://images.cocodataset.org/test-stuff2017/000000001750.jpg',
42 'http://images.cocodataset.org/test-stuff2017/000000000001.jpg'
43]
44
45images = []
46for url in urls:
47 image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
48 images.append(image)
49
50
51image_processor = transforms.Compose(
52 [
53 transforms.Resize((224, 224)),
54 transforms.ToTensor(),
55 transforms.Normalize(
56 mean=[0.485, 0.456, 0.406],
57 std=[0.47853944, 0.4732864, 0.47434163],
58 ),
59 ]
60)
61
62
63processed_images_onnx = [image_processor(image).unsqueeze(0) for image in images]
64
65# onnx needs numpy as input
66onnx_inputs = [item.numpy(force=True) for item in processed_images_onnx]
67
68# pack into a batch
69onnx_inputs = np.concatenate(onnx_inputs, axis=0)
70
71ort_session = onnxruntime.InferenceSession(
72 "./DocumentFigureClassifier-v2_5-onnx/model.onnx",
73 providers=["CUDAExecutionProvider", "CPUExecutionProvider"]
74)
75
76
77for item in ort_session.run(None, {'input': onnx_inputs}):
78 for x in iter(item):
79 pred = x.argmax()
80 print(LABELS[pred])@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}
}