Upload folder using huggingface_hub
Browse filesFiles changed (12)
- .gitattributes+5-34
- CITATION.cffAdded+25
- LICENSE.mdAdded+58
- README.md+139-1
- browser.htmlAdded+59
- detect.pyAdded+95
- docforensics-layout-s.jsonAdded+62
- docforensics-layout-s.onnxAdded+3
- examples/01-form-fields.pngAdded
- examples/02-same-page-degraded.pngAdded
- examples/03-typewritten-1967.pngAdded
- examples/04-where-it-loses.pngAdded
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text123456*.onnx filter=lfs diff=lfs merge=lfs -text*.pdf filter=lfs diff=lfs merge=lfs -textexamples/01-form-fields.png filter=lfs diff=lfs merge=lfs -textexamples/02-same-page-degraded.png filter=lfs diff=lfs merge=lfs -textexamples/03-typewritten-1967.png filter=lfs diff=lfs merge=lfs -textexamples/04-where-it-loses.png filter=lfs diff=lfs merge=lfs -text
12345678910111213141516171819202122232425cff-version: 1.2.0title: "docforensics-layout-s: document layout analysis for degraded pages"message: "If you use this model, please cite it."type: softwareauthors: - name: "Canworks, LLC" alias: "Ginexys" website: "https://ginexys.com" email: "contact@ginexys.com"version: "1.0.0"date-released: 2026-09-01license: AGPL-3.0-or-latercontact: - name: "Ginexys, a d/b/a of Canworks, LLC" email: "contact@ginexys.com"abstract: > An 8.8 MB document layout detector for damaged, scanned and photographed pages. Detects fifteen region types including form fields, and reports eight page-condition signals. Reaches 0.449 mAP@50-95 on degraded scans where a larger YOLOv8n baseline reaches 0.194.keywords: - document layout analysis - document forensics - degraded documents - form understanding12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758# Licence
`docforensics-layout-s` is published by **Ginexys**, a d/b/a of**Canworks, LLC**. https://ginexys.com
`docforensics-layout-s` is dual-licensed. Choose the track that fits your use.
## Track 1 — AGPL-3.0 (free)
Use, modify and redistribute freely under the GNU Affero General Public Licensev3.0. The obligation that matters: **if you run a modified version as a networkservice, you must publish your source to its users.** That covers a hosted API,a SaaS product, or an internal tool exposed over a network.
Suitable for research, evaluation, open-source projects, and personal use.
## Track 2 — Commercial licence (paid)
A commercial licence removes the AGPL copyleft obligation. You embed the modelin a closed-source product and publish nothing.
| tier | for | includes ||---|---|---|| Weights | teams wanting only the ONNX model | weights, manifest, no copyleft || Product | embedding in a commercial application | weights, worker integration, updates || Enterprise | volume or on-premise deployment | the above, plus support and a custom-training option |
To licence commercially, or to ask which tier applies to your use:
- **contact@ginexys.com** for pricing and evaluation- **legal@ginexys.com** for licence terms, redistribution and compliance
## Copyright
Copyright (c) 2026 Canworks, LLC. All rights reserved except as grantedabove.
Ginexys is a trading name of Canworks, LLC. Licences are granted by, andenforceable against, Canworks, LLC.
## What the licence covers
**The weights** (`docforensics-layout-s.onnx`) were trained entirely onCDLA-Permissive-1.0 material (DocLayNet, from IBM's primary distribution) andUS federal public-domain works (IRS forms, NASA technical reports, USPTOpublications) under 17 U.S.C. 105. No proprietary, scraped or unlicensedmaterial contributed to them, and no output of another model was distilled intothem.
**The surrounding pipeline** in the pdf-processor repository is AGPL-3.0independently of this model.
## Attribution for training data
- DocLayNet, IBM Research, CDLA-Permissive-1.0- IRS forms, US Internal Revenue Service, 17 U.S.C. 105- NASA technical reports, NTRS, 17 U.S.C. 105- Official Gazette of the USPTO, 17 U.S.C. 105, digitised by the Internet Archive123---license: agpl-3.0---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141---license: otherlicense_name: docforensics-duallicense_link: LICENSE.mdtags:- document-layout-analysis- object-detection- onnx- document-ai- ocr- formslibrary_name: onnxpipeline_tag: object-detection---# docforensics-layout-sA 8.8 MB document layout detector for **damaged, scanned and photographed pages**.Runs in a browser through onnxruntime-web, or anywhere ONNX runs. No GPU.It detects fifteen region types including form fields and checkboxes, and itreports eight page-condition signals (blur, skew, tearing, bleed-through,handwriting, and whether the page is a scan carrying an invisible OCR layer)that no comparable detector produces.## See it workClean, it ties with the baseline. Blurred, the baseline returns nothing andthis model still returns five regions — and the strip underneath reports theblur, which is the part no other detector does.**[More examples, including one this model loses](https://github.com/carnworkstudios/docforensics/tree/main/examples)**Every page is a United States federal work under 17 USC 105. Source URLs andthe script that regenerates the figures are in that directory.## What it is good atOn held-out degraded pages it reaches **0.449 mAP@50-95 where YOLOv8n-DocLayNetreaches 0.194**, at 71% of that model's size. Across 120 held-out degradedpages the baseline returned no regions at all on 14 of them; this model returnedmore regions on 104.| | this model | YOLOv8n-DocLayNet ||---|---:|---:|| size | **8.77 MB** | 12.27 MB || degraded mAP@50-95 | **0.449** | 0.194 || clean mAP@50-95 | 0.477 | **0.660** || form fields | **AP 0.670** | no such class || page-condition signals | **8** | none |## What it is not good at**Clean, born-digital pages rendered at high quality.** YOLOv8n-DocLayNet isbetter there, 0.660 against 0.477, and if that is your input you should use it.The deficit is uniform across all ten shared classes, which reflects parametercount rather than a class-specific weakness.**Picture-heavy magazine layout.** On a 1959 illustrated magazine page thebaseline found 17 regions to this model's 10, separating advertisement panelsand captions more finely.**Checkboxes at 640 px.** A checkbox is roughly 6.5 px at this input size, belowthe finest anchor stride, so AP is 0.153. Read them from the PDF's AcroFormwidgets instead when the page is born-digital.## Use it```pythonimport cv2, numpy as np, onnxruntime as ortCLASSES = ["text","heading","list","table","picture","caption","formula","header","footer","footnote","seal","form","field","checkbox","signature"]sess = ort.InferenceSession("docforensics-layout-s.onnx",providers=["CPUExecutionProvider"])def letterbox(img, side=640):h, w = img.shape[:2]s = side / max(h, w)small = cv2.resize(img, (int(w * s), int(h * s)))canvas = np.full((side, side, 3), 114, np.uint8)canvas[:small.shape[0], :small.shape[1]] = smallreturn canvasimg = letterbox(cv2.imread("page.png"))x = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0x = ((x - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]).transpose(2, 0, 1)[None]det, signals, maps = sess.run(None, {"images": x.astype(np.float32),"evidence": np.zeros((1, 4), np.float32)})# det is [1, 19, 8500]: rows 0-3 are cx,cy,w,h in 640px space, rows 4-18 are# per-class scores. Apply your own confidence threshold and NMS.boxes, scores = det[0, :4].T, det[0, 4:].Tkeep = scores.max(1) > 0.18print(f"{keep.sum()} candidate regions before NMS")# signals is [1, 8]: skew, blur, noise, bleed, warp, tears, handwriting, nativeprint(dict(zip(["skew","blur","noise","bleed","warp","tears","hand","native"],signals[0].round(3))))```Outputs are YOLOv8-shaped on purpose, so any existing YOLOv8 decode and NMSworks unchanged.## Inputs`images` is `[1, 3, 640, 640]`, RGB, ImageNet-normalised, letterboxed with fillvalue 114. `evidence` is `[1, 4]` and may be all zeros; it carries optionaldeterministic page flags and is reserved for future use.## How it was trained68k DocLayNet pages under a synthetic degradation pipeline covering skew, blur,sensor noise, bleed-through, perspective warp, physical tearing and aged-paperfading, plus 2,184 form pages labelled directly from AcroForm widget geometryand 6,821 pages labelled by a deterministic vector extractor. Training data isCDLA-Permissive-1.0 (DocLayNet) and US federal public domain (IRS forms, NASAtechnical reports). No proprietary or unlicensed material was used.## LicenceDual-licensed, AGPL-3.0 or commercial. See `LICENSE.md`.Published by **Ginexys**, a d/b/a of **Canworks, LLC**.Commercial licensing: contact@ginexys.com.Licence terms and compliance: legal@ginexys.com.The weights are separable from the surrounding pipeline and were trainedentirely on permissively licensed and public-domain data.## CitationSee `CITATION.cff`.A technical report documents the evaluation methodology, including a measureddecorrelation between detection mAP and downstream extraction quality. It isnot published yet; write to contact@ginexys.com if you need it before then.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859<!doctype html><meta charset="utf-8"><title>docforensics browser demo</title><style> body { font: 15px/1.6 system-ui, sans-serif; max-width: 900px; margin: 40px auto; padding: 0 20px } canvas { border: 1px solid #ddd; max-width: 100%; margin-top: 16px } #signals { font-family: ui-monospace, monospace; font-size: 13px; background: #f6f6f4; padding: 12px; border-radius: 4px; margin-top: 14px } .row { display: flex; gap: 20px; flex-wrap: wrap }</style>
<h1>docforensics</h1><p>Layout detection for scanned and damaged pages, running entirely in this tab. Nothing is uploaded.</p>
<input type="file" id="file" accept="image/*"><div class="row"> <canvas id="out"></canvas> <div id="signals">load a page image</div></div>
<script type="module">import * as ort from 'https://cdn.jsdelivr.net/npm/onnxruntime-web/dist/esm/ort.min.js';import { load, detect } from 'https://esm.sh/@canwork/docforensics';
const COLOURS = { text:'#3cb44b', heading:'#e6194b', list:'#ffe119', table:'#0082c8', picture:'#f58231', caption:'#911eb4', field:'#3cdc5a', checkbox:'#e60000', form:'#ff8c00', header:'#f032e6', footer:'#d2f53c' };
const model = await load('docforensics-layout-s', ort);
document.getElementById('file').onchange = async (e) => { const img = new Image(); img.src = URL.createObjectURL(e.target.files[0]); await img.decode();
const src = document.createElement('canvas'); src.width = img.width; src.height = img.height; src.getContext('2d').drawImage(img, 0, 0);
const { regions, signals } = await detect(model, src);
const out = document.getElementById('out'); out.width = img.width; out.height = img.height; const g = out.getContext('2d'); g.drawImage(img, 0, 0); g.lineWidth = Math.max(2, img.width / 400); g.font = `${Math.max(11, img.width / 70)}px sans-serif`; for (const r of regions) { g.strokeStyle = g.fillStyle = COLOURS[r.label] || '#888'; g.strokeRect(r.bbox.x, r.bbox.y, r.bbox.w, r.bbox.h); g.fillText(`${r.label} ${r.score.toFixed(2)}`, r.bbox.x, r.bbox.y - 4); }
document.getElementById('signals').textContent = `${regions.length} regions\n\n` + Object.entries(signals).map(([k, v]) => `${k.padEnd(12)} ${v.toFixed(3)}`).join('\n');};</script>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495#!/usr/bin/env python"""detect.py -- run docforensics on a page image and draw the regions.
python detect.py page.png [out.png]
Needs: onnxruntime, opencv-python, numpy."""import sysimport cv2import numpy as npimport onnxruntime as ort
CLASSES = ["text", "heading", "list", "table", "picture", "caption", "formula", "header", "footer", "footnote", "seal", "form", "field", "checkbox", "signature"]SIGNALS = ["skew", "blur", "noise", "bleed", "warp", "tears", "handwriting", "native"]COLOURS = {"text": (75, 180, 60), "heading": (75, 25, 230), "list": (25, 225, 255), "table": (200, 130, 0), "picture": (48, 130, 245), "caption": (180, 30, 145), "field": (90, 220, 60), "checkbox": (230, 0, 0), "form": (0, 140, 255)}CONF, IOU = 0.18, 0.5
def letterbox(img, side=640): """Match training preprocessing exactly: fit long side, pad with 114.""" h, w = img.shape[:2] s = side / max(h, w) small = cv2.resize(img, (int(w * s), int(h * s))) canvas = np.full((side, side, 3), 114, np.uint8) canvas[:small.shape[0], :small.shape[1]] = small return canvas
def nms(boxes, scores, thr): order = scores.argsort()[::-1] keep = [] while order.size: i = order[0] keep.append(i) if order.size == 1: break xx1 = np.maximum(boxes[i, 0], boxes[order[1:], 0]) yy1 = np.maximum(boxes[i, 1], boxes[order[1:], 1]) xx2 = np.minimum(boxes[i, 2], boxes[order[1:], 2]) yy2 = np.minimum(boxes[i, 3], boxes[order[1:], 3]) inter = np.maximum(0, xx2 - xx1) * np.maximum(0, yy2 - yy1) a = (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1]) order = order[1:][inter / (a[i] + a[order[1:]] - inter) <= thr] return keep
def detect(path, model="docforensics-layout-s.onnx"): raw = cv2.imread(path) if raw is None: sys.exit(f"cannot read {path}") img = letterbox(raw) x = cv2.cvtColor(img, cv2.COLOR_BGR2RGB).astype(np.float32) / 255.0 x = ((x - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225]) x = x.transpose(2, 0, 1)[None].astype(np.float32)
sess = ort.InferenceSession(model, providers=["CPUExecutionProvider"]) det, signals, _maps = sess.run( None, {"images": x, "evidence": np.zeros((1, 4), np.float32)})
# det is [1, 4+15, 8500] in YOLOv8 row order: cx, cy, w, h, then per-class # scores. Any YOLOv8 decode works unchanged. d = det[0].T cx, cy, bw, bh = d[:, 0], d[:, 1], d[:, 2], d[:, 3] xyxy = np.stack([cx - bw / 2, cy - bh / 2, cx + bw / 2, cy + bh / 2], 1) scores, labels = d[:, 4:].max(1), d[:, 4:].argmax(1)
out = [] for c in np.unique(labels[scores > CONF]): m = (labels == c) & (scores > CONF) for i in nms(xyxy[m], scores[m], IOU): out.append((xyxy[m][i], scores[m][i], CLASSES[c])) return img, out, dict(zip(SIGNALS, signals[0].round(3).tolist()))
if __name__ == "__main__": if len(sys.argv) < 2: sys.exit(__doc__) img, regions, signals = detect(sys.argv[1]) for box, score, name in regions: c = COLOURS.get(name, (150, 150, 150)) cv2.rectangle(img, (int(box[0]), int(box[1])), (int(box[2]), int(box[3])), c, 2) cv2.putText(img, f"{name} {score:.2f}", (int(box[0]), max(10, int(box[1]) - 4)), cv2.FONT_HERSHEY_SIMPLEX, 0.35, c, 1) print(f"{len(regions)} regions") for k, v in signals.items(): print(f" {k:12s} {v:.3f}") dst = sys.argv[2] if len(sys.argv) > 2 else "out.png" cv2.imwrite(dst, img) print(f"wrote {dst}")1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162{ "id": "docforensics-layout-s", "line": "layout", "scale": "s", "run_id": "w160", "sizeBytes": 8773229, "sizeMB": 8.773, "sha256": "c148e85957c772c55364288469f461b4a146c3e6a9b46bd3e7e8647c79896721", "opset": 18, "opsetRequested": 17, "inputSize": 640, "normalisation": "imagenet", "classes": [ "text", "heading", "list", "table", "picture", "caption", "formula", "header", "footer", "footnote", "seal", "form", "field", "checkbox", "signature" ], "detectionLayout": "yolov8", "outputs": [ "detections", "forensic_signals", "forensic_maps" ], "forensics": { "signalOrder": [ "skew", "blur", "noise", "bleed", "warp", "tears", "handwriting", "native" ], "mapOrder": [ "blur", "bleed", "tears", "handwriting" ], "mapGrid": 20 }, "trainedEpoch": 8, "bestValMAP": 0.49916167018408547, "parityMaxAbsErr": { "forensic_signals": 4.470348358154297e-07, "forensic_maps": 8.940696716308594e-07 }, "tensorDigestSha256": "035e9f4f1f226a80e024c2979073966c19bd7e537dd63a10126a57ea1e611c54"}123version https://git-lfs.github.com/spec/v1oid sha256:c148e85957c772c55364288469f461b4a146c3e6a9b46bd3e7e8647c79896721size 8773229.gitattributes+5-34
CITATION.cffAdded+25
LICENSE.mdAdded+58
README.md+139-1
browser.htmlAdded+59
detect.pyAdded+95
docforensics-layout-s.jsonAdded+62
docforensics-layout-s.onnxAdded+3
examples/01-form-fields.pngAdded

Large File Pointer Details
- SHA256: 696d87f2b81eb07bb002696189bc6ffa6b206893a3635f4ca4f1b36f930ce5d5
- Pointer size: 131 Bytes
- Size of remote file: 229 kB
examples/02-same-page-degraded.pngAdded

Large File Pointer Details
- SHA256: 6659e12a5b8eedac719f6c382645ddd3cf481cf9186e5d20e0c8307c6fb051e2
- Pointer size: 131 Bytes
- Size of remote file: 531 kB
examples/03-typewritten-1967.pngAdded

Large File Pointer Details
- SHA256: f2c04e79b7283c4e5660f7742f8b0d7eecdcceb66c52b30927b8d83bb53ea69d
- Pointer size: 131 Bytes
- Size of remote file: 604 kB
examples/04-where-it-loses.pngAdded

Large File Pointer Details
- SHA256: bb1b08c43e6d71f33d19ca6ff6fe0fc35145a16eb9597e0a03a93a627a2f880d
- Pointer size: 131 Bytes
- Size of remote file: 288 kB