Views
No views yet
onnxruntime inference without the PaddlePaddle runtime dependency.paddle2onnx 1.3.1 with opset_version=16| File | Size | Purpose |
|---|---|---|
slanet_1m.onnx | 7.6 MB | ONNX-exported model weights |
inference.yml | 1.3 KB | Preprocessing config + 28-token character dictionary |
.pdmodel + .pdiparams) which require installing the full paddlepaddle package (~300 MB) for inference. This repo provides the same trained weights in ONNX so they can be loaded with just onnxruntime.paddle2onnx performs a graph-to-graph translation, not retraining or quantization. SHA-256 of the produced slanet_1m.onnx:8a8aa31bf964c1c05039f02814e5f425a354a37552eaca8e6d5dc513048759f51pip install paddlepaddle paddle2onnx==1.3.1
2huggingface-cli download dimtri009/SLANet-1M --local-dir ./slanet-1m-paddle
3paddle2onnx \
4 --model_dir ./slanet-1m-paddle \
5 --model_filename inference.pdmodel \
6 --params_filename inference.pdiparams \
7 --save_file slanet_1m.onnx \
8 --opset_version 161import cv2
2import numpy as np
3import onnxruntime as ort
4import yaml
5
6# Load model and char dict
7session = ort.InferenceSession("slanet_1m.onnx", providers=["CPUExecutionProvider"])
8config = yaml.safe_load(open("inference.yml"))
9character_dict = config["PostProcess"]["character_dict"]
10
11# Preprocess: BGR → resize longest side ≤488 → ImageNet normalize → pad to 488×488 → CHW
12def preprocess(img_bgr, max_len=488):
13 h, w = img_bgr.shape[:2]
14 ratio = max_len / max(h, w)
15 rh, rw = int(h * ratio), int(w * ratio)
16 resized = cv2.resize(img_bgr, (rw, rh))
17 mean = np.array([0.485, 0.456, 0.406])
18 std = np.array([0.229, 0.224, 0.225])
19 norm = (resized.astype(np.float32) / 255.0 - mean) / std
20 padded = np.zeros((max_len, max_len, 3), dtype=np.float32)
21 padded[:rh, :rw] = norm
22 chw = padded.transpose(2, 0, 1)
23 return chw[None].astype(np.float32), [h, w, ratio, ratio, max_len, max_len]
24
25img = cv2.imread("table.png")
26batch, shape_info = preprocess(img)
27bbox_preds, struct_probs = session.run(None, {"x": batch})
28
29# Decode: argmax over struct_probs → token indices → HTML; index bbox_preds for <td> tokens
30# Full decoder: see PaddleOCR's TableLabelDecode or rapid_table's pp_structure post_process| Property | Value |
|---|---|
| Parameters | ~9.2M |
| Input size | 488×488 RGB (variable, padded to square) |
| Output 1 | (N, T, 4) xyxy bbox per structure token |
| Output 2 | (N, T, 30) structure-token logits |
| Vocab | 28 PaddleOCR table tokens + sos + eos |
| S-TEDS (PubTabNet, author-reported) | 97.36 |
| S-TEDS (SynthTabNet, author-reported) | 99.36 |