Commit Β·
62b1049
0
Parent(s):
form-field-v1 release
Browse files- .gitattributes +35 -0
- README.md +88 -0
- model.onnx +3 -0
- state_cnn.pt +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pipeline_tag: image-classification
|
| 4 |
+
library_name: onnxruntime
|
| 5 |
+
language: [en]
|
| 6 |
+
tags:
|
| 7 |
+
- image-classification
|
| 8 |
+
- document-ai
|
| 9 |
+
- form-field-detection
|
| 10 |
+
- onnx
|
| 11 |
+
- open-weights
|
| 12 |
+
metrics:
|
| 13 |
+
- accuracy
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# form-field-v1-state β open-weight
|
| 17 |
+
|
| 18 |
+
**A 96k-parameter filled/empty classifier for detected form fields.** Given a cropped field, it reads whether
|
| 19 |
+
the field is **filled** (filled / checked / signed) or **empty** (empty / unchecked / blank) β a single shared,
|
| 20 |
+
detector-agnostic model that supplies state for any of the `form-field-v1` detectors. ~0.4 MB, CPU-fast,
|
| 21 |
+
Apache-2.0, runs via ONNX Runtime with no custom code.
|
| 22 |
+
|
| 23 |
+
Part of the `form-field-v1` family β pair it with [`-nano`](https://huggingface.co/nutrientdocs/form-field-v1-nano)
|
| 24 |
+
(open) or [`-small`](https://huggingface.co/nutrientdocs/form-field-v1-small) /
|
| 25 |
+
[`-medium`](https://huggingface.co/nutrientdocs/form-field-v1-medium) (commercial).
|
| 26 |
+
|
| 27 |
+
- π― **Try it:** [form-field-v1-demo](https://huggingface.co/spaces/nutrientdocs/form-field-v1-demo)
|
| 28 |
+
- π **Leaderboard:** [form-field-v1-leaderboard](https://huggingface.co/spaces/nutrientdocs/form-field-v1-leaderboard)
|
| 29 |
+
- π **Benchmark:** [form-field-v1-benchmark](https://huggingface.co/datasets/nutrientdocs/form-field-v1-benchmark)
|
| 30 |
+
|
| 31 |
+
## What it does
|
| 32 |
+
|
| 33 |
+
Field detectors locate `Text`, `Choice`, and `Signature` widgets; this model answers the follow-up question
|
| 34 |
+
**"is that field filled?"** on the detected crop. It takes a grayscale field crop, letterboxes it to **40Γ160**
|
| 35 |
+
(aspect-preserving β form fields are wide, median aspect ~3.3, so a square resize destroys thin printed text),
|
| 36 |
+
and outputs a binary **empty (0) / filled (1)** label. State is mapped per type: Text β filled/empty,
|
| 37 |
+
Choice β checked/unchecked, Signature β signed/blank.
|
| 38 |
+
|
| 39 |
+
## Results
|
| 40 |
+
|
| 41 |
+
Binary field-state accuracy, one shared evaluation.
|
| 42 |
+
|
| 43 |
+
| | Accuracy |
|
| 44 |
+
|---|---|
|
| 45 |
+
| **form-field-v1-state** (this model) | **0.981** |
|
| 46 |
+
| Training-free ink heuristic | 0.915 |
|
| 47 |
+
|
| 48 |
+
On a held-out synthetic split it reaches **0.981** vs a training-free ink-presence heuristic's **0.915**. On a
|
| 49 |
+
real filled form (the ACME credit-card application, 25 fields) it matches the heuristic at **23/25**.
|
| 50 |
+
|
| 51 |
+
## What's in this repo
|
| 52 |
+
| File | |
|
| 53 |
+
|---|---|
|
| 54 |
+
| `model.onnx` | ONNX graph, input `1Γ1Γ40Γ160` grayscale, output `logits [n,2]` |
|
| 55 |
+
| `state_cnn.pt` | PyTorch state dict (depthwise-separable CNN, 96k params) |
|
| 56 |
+
|
| 57 |
+
Classes: `0 = empty`, `1 = filled`.
|
| 58 |
+
|
| 59 |
+
## Usage (ONNX Runtime)
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
import numpy as np, onnxruntime as ort
|
| 63 |
+
from PIL import Image
|
| 64 |
+
|
| 65 |
+
sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
|
| 66 |
+
|
| 67 |
+
def letterbox(crop, th=40, tw=160): # aspect-preserving, pad 255 (paper)
|
| 68 |
+
g = crop.convert("L"); w, h = g.size
|
| 69 |
+
s = min(tw / w, th / h); nw, nh = max(1, round(w * s)), max(1, round(h * s))
|
| 70 |
+
out = Image.new("L", (tw, th), 255); out.paste(g.resize((nw, nh), Image.BILINEAR), ((tw - nw) // 2, (th - nh) // 2))
|
| 71 |
+
return np.asarray(out, np.uint8)
|
| 72 |
+
|
| 73 |
+
crop = Image.open("field_crop.png") # a detected field, cropped from the page
|
| 74 |
+
x = (((letterbox(crop).astype(np.float32) / 255) - 0.5) / 0.5)[None, None] # normalize, shape [1,1,40,160]
|
| 75 |
+
filled = int(sess.run(None, {sess.get_inputs()[0].name: x})[0].argmax(1)[0]) == 1
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## License & data
|
| 79 |
+
Apache-2.0. Trained on synthetic form renders (empty + filled + handwritten field crops, with on-the-fly
|
| 80 |
+
augmentation for scan robustness); no PII.
|
| 81 |
+
|
| 82 |
+
## About the author
|
| 83 |
+
|
| 84 |
+
<a href="https://nutrient.io/">
|
| 85 |
+
<img src="https://avatars2.githubusercontent.com/u/1527679?v=3&s=200" height="80" />
|
| 86 |
+
</a>
|
| 87 |
+
|
| 88 |
+
This project is maintained and funded by [Nutrient](https://nutrient.io/) - The deterministic document infrastructure enterprises run their highest-stakes workflows on: replayable output, clear exceptions, and full audit trails on the messy, regulated documents where AI alone breaks.
|
model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7afb50c85247174b5384e4fa857b8a56a1736a40057981904f995952c2444974
|
| 3 |
+
size 383549
|
state_cnn.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:88560abc622a1a6aae911512881093550819f06c3e53a3b9927ed370b52919a6
|
| 3 |
+
size 416457
|