pagepose / README.md
gregbugaj's picture
Upload folder using huggingface_hub
ade1db2 verified
|
Raw History Blame Contribute Delete
12.3 kB
---
license: apache-2.0
library_name: pagepose
pipeline_tag: image-classification
base_model: Qwen/Qwen3.5-4B
base_model_relation: finetune
tags:
- document-ai
- document-rotation
- image-classification
- page-orientation
- qwen3.5
- vision
metrics:
- accuracy
model-index:
- name: PagePose Qwen3.5-4B Vision
results:
- task:
type: image-classification
name: Document rotation classification
dataset:
type: private
name: Curated private held-out pages
split: test
metrics:
- type: accuracy
name: Exact 12-class accuracy
value: 96.996996996997
- task:
type: image-classification
name: Document rotation classification
dataset:
type: krutrim-ai-labs/ocr_rotation_bench
name: ORB-En
split: test
metrics:
- type: accuracy
name: Exact 12-class accuracy
value: 100
- task:
type: image-classification
name: Document rotation classification
dataset:
type: konfuzio/funsd_plus
name: FUNSD+-Test
split: test
metrics:
- type: accuracy
name: Exact 12-class accuracy
value: 100
---
# PagePose Qwen3.5-4B Vision
PagePose Qwen3.5-4B Vision is a vision-only document-orientation classifier. It predicts the
clockwise displacement of a page from upright in twelve 30-degree classes: `0`, `30`, `60`, `90`,
`120`, `150`, `180`, `210`, `240`, `270`, `300`, and `330` degrees.
Despite the upstream model name, this is not a four-billion-parameter language model. PagePose
extracts and fine-tunes only the pinned Qwen3.5-4B vision encoder and merger, then adds dynamic
document-crop pooling and a classification head. It does not load a tokenizer, token embeddings,
language decoder, or language-model head.
> **Release status:** This card describes the frozen final model and can be published for review.
> The evaluated local checkpoint is not a public release artifact: it includes optimizer,
> scheduler, and RNG state and uses PyTorch pickle serialization. Do not upload it. Public weights
> remain gated on an inference-only export, parity verification, and explicit privacy, legal, and
> data-rights approval.
## Model details
| Property | Value |
| --- | --- |
| Task | Twelve-class document rotation classification |
| Output semantics | Clockwise page displacement from upright |
| Correction | Inverse angle: `(-detected_rotation) % 360` |
| Upstream model | `Qwen/Qwen3.5-4B` |
| Pinned upstream revision | `851bf6e806efd8d0a36b00ddf55e13ccb7b8cd0a` |
| Vision parameters | 333,514,240 |
| Total PagePose parameters | 336,807,692 |
| Internal crop size | 320 x 320 RGB |
| Crop workload | 16 local crops plus one global crop |
| Confidence gate | 0.80 |
| Dataset fingerprint | `37422683263345a3146f36ea22cbca3be9482073a2434d069cfa7b619c9afbfc` |
| Evaluated checkpoint SHA-256 | `b408171e228beb2449934340cc6dae122dab16c568ee0edd089b012e26d8388b` |
| Evaluation date | 2026-08-26 |
The checkpoint hash identifies the private training-resume checkpoint used to produce the results
below. It will not identify the future public inference artifact.
## Intended use
Use PagePose to detect coarse page orientation before OCR, document extraction, indexing, or human
review. It accepts raster document images with varying dimensions. PagePose preserves aspect ratio
while creating its document crops internally, so callers should not squash a page to 320 x 320.
The PagePose runtime returns the detected clockwise displacement, inverse correction angle,
confidence, all twelve class probabilities, and an `orientation_unknown` flag when confidence is
below the configured gate. It can also apply the inverse rotation to produce an upright page.
This model is not intended for OCR, handwriting recognition, content extraction, document
classification, arbitrary-angle deskewing, or interpreting page meaning. It is not a
Transformers-native `AutoModelForImageClassification` model and cannot be loaded through the
generic Transformers image-classification pipeline.
## Usage
The final weights have not been published. An approved local checkpoint can be converted to the
safe inference directory format with the compatible PagePose package:
```bash
git clone https://github.com/gregbugaj/pagepose.git
cd pagepose
uv sync --extra cu130
uv run pagepose-export-artifact \
--checkpoint /path/to/approved-training-checkpoint/best.pt \
--output /path/to/pagepose-qwen35-4b-v1
```
```python
from pagepose import DocumentRotationModel
model = DocumentRotationModel.from_pretrained(
"/path/to/pagepose-qwen35-4b-v1",
device="cuda",
)
result = model.predict("page.png")
print(result.detected_rotation) # clockwise displacement from upright
print(result.correction_rotation) # clockwise correction to apply
print(result.confidence)
print(result.orientation_unknown)
if not result.orientation_unknown:
corrected = model.correct_orientation("page.png")
corrected.save("page-upright.png")
```
The inference directory contains safetensors weights, sanitized inference configuration, Marie
identity metadata, and a checksum manifest. PagePose validates those files before constructing the
model and requires the package version recorded by the artifact.
## Training data
Training used 539 operator-reviewed upright RGB document pages from a private corpus. The split was
315 source pages for training, 113 for validation, and 111 for held-out testing. Validation and test
evaluated every source page at all twelve rotations. Training used an online deterministic cyclic
rotation schedule.
The corpus retains pseudonymous IDs but no original filenames or selection-corpus labels. A
detached overlap audit compared all 539 private pages with 200 FUNSD reference pages and found zero
encoded-checksum overlaps and zero decoded-RGB-pixel overlaps.
The private images are not included in this model repository or in the PagePose source
distribution. They may contain sensitive information or PHI, which is why publishing trained
weights requires separate privacy, legal, and data-rights approval.
## Training procedure
The vision backbone and PagePose classification layers were fully fine-tuned in BF16 with AdamW,
a constant learning rate of `1e-5`, weight decay `0.01`, effective batch size 64, seed 42, and
early-stopping patience 7. Each page used sixteen 320-pixel local crops plus one global crop.
Merged Qwen visual tokens were pooled per crop, crop representations were mean-pooled per document,
and a dropout/linear/GELU/linear head produced twelve logits.
The selected checkpoint was epoch index 31 at 97.9351% validation accuracy. Early stopping
completed 39 epochs, through epoch index 38, in 8,438.593 seconds on one NVIDIA GeForce RTX 4090.
Peak allocated training memory was 7,421,987,328 bytes.
## Evaluation
All results use the selected checkpoint and the production crop workload of sixteen local crops
plus one global crop.
| Evaluation | Independent pages | Correct views | Accuracy | Mean angular error |
| --- | ---: | ---: | ---: | ---: |
| Private validation | 113 | 1,328 / 1,356 | 97.9351% | Not reported |
| Private held-out test | 111 | 1,292 / 1,332 | 96.9970% | 2.905 degrees |
| ORB-En official file | 50 | 50 / 50 | 100.0000% | 0 degrees |
| FUNSD+-Test | 113 | 1,356 / 1,356 | 100.0000% | 0 degrees |
The private validation-to-test difference is 0.9381 percentage points. Private held-out testing
had 40 incorrect rotated views, expected calibration error of 0.021930, and 121 views (9.0841%)
below the 0.80 confidence threshold.
The selected checkpoint was chosen only by private validation accuracy. The private test, ORB-En,
and FUNSD+-Test results were not used for checkpoint selection. FUNSD+-Test was not used for
training, validation, early stopping, or checkpoint selection. Evaluation rotations derived from
the same source page are correlated; the independent-page counts are therefore more informative
than treating all rotated views as independent samples.
ORB-En was evaluated from the official `orb_en_12_class.parquet` as stored. FUNSD+-Test used the
reviewed test split of `konfuzio/funsd_plus` at pinned revision
`54c474670518f6e219360a9d5195c027f8bebfd3`, with all twelve rotations generated during evaluation.
Neither external benchmark is redistributed with PagePose.
See the [canonical benchmark report](https://github.com/gregbugaj/pagepose/blob/main/BENCHMARK.md)
for checksums, angle-level private results, benchmark provenance, and exact reproduction commands.
## Inference performance
Warm inference was measured on one NVIDIA GeForce RTX 4090 with Python 3.12.3, PyTorch
2.12.1+cu130, and CUDA runtime 13.0. The controlled input was an unchanged 2554 x 3297 RGB page.
Measurements include preprocessing, dynamic crop creation, synchronized GPU inference, and result
decoding, but exclude model and checkpoint loading.
| Batch | Images/s | Per image | P50 batch | P95 batch | Peak allocated GPU memory |
| ---: | ---: | ---: | ---: | ---: | ---: |
| 1 | 7.109 | 140.66 ms | 140.69 ms | 142.56 ms | 1,705,602,560 bytes |
| 4 | 6.727 | 148.66 ms | 594.93 ms | 598.91 ms | 2,749,910,016 bytes |
| 8 | 6.784 | 147.40 ms | 1,182.54 ms | 1,188.15 ms | 4,140,377,088 bytes |
| 16 | 6.666 | 150.01 ms | 2,401.18 ms | 2,427.21 ms | 6,920,654,848 bytes |
| 32 | 6.346 | 157.59 ms | 4,910.03 ms | 5,539.24 ms | 12,482,521,600 bytes |
These numbers describe this machine and workload; they are not hardware-independent latency
guarantees.
## Limitations and risks
- The model predicts only multiples of 30 degrees and does not replace fine skew correction.
- Sparse pages, rotationally symmetric layouts, unusual scripts, photographs, and ambiguous page
content may produce unreliable orientation predictions.
- ORB-En and FUNSD+-Test emphasize English-language and form documents. No ORB-Indic result is
reported.
- The external evaluations contain only 50 and 113 independent source pages. Perfect accuracy on
these finite sets does not establish perfect deployment accuracy or general superiority.
- Confidence is not a guarantee of correctness. Applications should preserve the confidence gate
and route uncertain or high-impact pages to a safe fallback or review path.
- The training corpus consists of private documents that may contain PHI. No images or OCR text
are packaged and the classifier does not emit document text, but resistance to membership
inference or training-data extraction has not been established.
- Document-domain coverage is not a demographic fairness evaluation. Performance can vary by
language, capture device, page condition, layout, and document source.
## Release artifact requirements
The evaluated `best.pt` is a 4,042,077,981-byte training-resume checkpoint. It contains optimizer,
scheduler, and RNG state and uses PyTorch pickle serialization. It must not be uploaded to the
public model repository.
A releasable artifact must contain inference-only weights, use safe serialization supported by the
PagePose runtime, omit private paths and training state, pass prediction-parity checks against the
evaluated checkpoint, and record its filename, byte size, and SHA-256 here. The release must also
pin a compatible PagePose package or immutable source revision. Completing those technical steps
does not replace the required privacy, legal, and data-rights approval.
## License and references
PagePose code and the upstream [Qwen3.5-4B model](https://huggingface.co/Qwen/Qwen3.5-4B) use the
Apache-2.0 license. Evaluation datasets remain governed by their own terms and are not
redistributed here. The Apache-2.0 metadata on this card does not itself grant rights to release
weights derived from the private training corpus.
- [PagePose source](https://github.com/gregbugaj/pagepose)
- [Benchmark methodology and evidence](https://github.com/gregbugaj/pagepose/blob/main/BENCHMARK.md)
- [ORB dataset](https://huggingface.co/datasets/krutrim-ai-labs/ocr_rotation_bench)
- [FUNSD+ dataset](https://huggingface.co/datasets/konfuzio/funsd_plus)
- [ORB paper: Seeing Straight: Document Orientation Detection for Efficient OCR](https://arxiv.org/abs/2511.04161)