Folio Page Layout
Folio Page Layout helps a digitizer decide whether to keep a scan whole, split two facing pages, or send the image to review. It runs locally on CPU. The output is one decision for the entire frame. Locating the binding and choosing the cut position are separate steps. Folio Fold binding locator
Try a book opening
Open the spread viewer, choose a local image, then select Check page layout. The first check loads the compact model. On the included illustrated book, both classifiers suggest splitting the facing pages. You can inspect the proposed cut before using it. Open the spread viewer · Download the illustrated book scan
Install the runtime and download the four files below. The example is an open illustrated book from The Metropolitan Museum of Art. Replace example.png with a scan of your own.
python -m pip install huggingface_hub onnxruntime numpy Pillow
hf download foliokestrel/folio-page-layout model.onnx config.json layout.py example.png --local-dir folio-page-layout
cd folio-page-layout
python layout.py example.png
The example returns a split score of about 0.859 and the action split. A score of 0.20 or below produces whole, and 0.80 or above produces split. Scores between those thresholds produce review. The binary proposal field uses a threshold of 0.5. The scores are uncalibrated. The command applies EXIF orientation, composites transparency over white and reads one frame at a time. Select a page from a multi-frame TIFF before passing it to the classifier.
Smaller download
The compact graph takes 44.5 MB. To use it on a laptop, install the same runtime as above and download these files. You can run subsequent checks offline.
hf download foliokestrel/folio-page-layout compact/model.onnx config.json layout.py example.png --local-dir folio-page-layout
cd folio-page-layout
python layout.py --compact example.png
Add --compare to see both classifiers. Python callers can select the same graph with LayoutProbe(".", compact=True). The 88.4 MB full-precision graph remains the default.
The compact graph stores 74 large weight arrays in half precision and casts them to float32 during evaluation. This reduces the download by 49.7%. Across 1,032 views of 344 images on CPU, both classifiers matched every binary proposal and every three-way decision from the frozen reference. The largest absolute score difference was 0.000662. In Chromium, the 46 original Chicago images gave the same decisions for both classifiers, with a maximum score difference of 0.000449. On other images, small score changes near a threshold can change a decision. Verification by collection and runtime · Conversion script
Make a page inventory for a scanned PDF
To find pages that need a layout check before you split a book, run the classifier over the PDF in page order. The command writes a CSV you can open in a spreadsheet. Each row has a one-based PDF page number, the suggested action and a split score.
python -m pip install huggingface_hub onnxruntime numpy Pillow 'pypdfium2>=5,<6'
hf download foliokestrel/folio-page-layout layout_pdf.py layout.py config.json compact/model.onnx examples/hokusai-sample.pdf --local-dir folio-page-layout
cd folio-page-layout
python layout_pdf.py --compact examples/hokusai-sample.pdf
python layout_pdf.py --compact book.pdf > inventory.csv
The two-page sample comes from Hokusai’s eighth sketchbook. The original classifier marks the cover whole (0.096) and the open preface split (0.901). Replace book.pdf with your own PDF path. Museum record
Filter the action column to review to see which pages fall between the model’s decision thresholds. Check suggested splits against the source before cutting. For a comparison of both classifiers, add --compare. Use --format jsonl for one JSON object per page. To use the full-precision weights, download the root model.onnx and omit --compact.
PDFium renders each displayed page with its crop, rotation and visible annotations, scaling its longest edge to 1,280 pixels. Margins, rotation and rendering resolution can affect the decision. Page numbers refer to positions in the PDF, including covers. The command writes the inventory after all pages succeed and leaves the source PDF intact. An encrypted PDF that requires a password must first be opened and saved as a readable local copy.
For results on the Smithsonian design book and Harvard notebook, see the paired comparisons of JPEG previews, image-only PDFs and archive PDF editions. PDF evaluation by book
Process several scans
Create one session and reuse it across images. From the directory created above, this example prints one JSON record per PNG in a directory of scans.
import json
from pathlib import Path
from PIL import Image
from layout import LayoutProbe
probe = LayoutProbe(".", threads=2)
for path in sorted(Path("scans").glob("*.png")):
with Image.open(path) as image:
result = probe.predict(image)["original"]
print(json.dumps({"file": str(path), **result}))
Choosing a classifier
The default uses the original head trained on 147 whole images and spreads from the Cleveland Museum of Art. A second head was fitted on the same images with landscape and portrait padding added during training. Both use the same frozen encoder. To inspect both results, pass --compare to the command or read the mount_trained result from predict.
On 46 Chicago photographs selected after both heads were frozen, one reviewer identified 31 whole images, 10 spreads and 5 ambiguous cases before scoring. The table counts only the 41 clear cases. The portrait condition adds centered gray padding around each photograph. These are repeated views of the same objects.
| Test input | Head | Correctly kept whole / 31 | Correctly split / 10 | Sent to review / 41 | Accepted errors |
|---|---|---|---|---|---|
| Original photograph | Original | 25 | 9 | 7 | 0 |
| Original photograph | Mount-trained | 25 | 7 | 9 | 0 |
| Portrait canvas | Original | 28 | 1 | 12 | 0 |
| Portrait canvas | Mount-trained | 25 | 8 | 8 | 0 |
Margins changed which classifier recognized more spreads. Among the five ambiguous originals, the original head sent three to review and the mount-trained head sent one. Elsewhere, the original head made five accepted errors among 65 accepted native cBAD archival scans. Check the decisions on material from your own scanning setup before applying cuts.
Model and reproduction
The 88,446,913-byte ONNX graph accepts a single uint8[224,224,3] RGB array named rgb. Resize the entire displayed image using Pillow bicubic interpolation. The graph normalizes the pixels internally. It combines the DINOv2-Small class token with averaged patch features from four vertical strips and returns split_scores in the order [original, mount_trained]. Graph checksum, output order and thresholds are stored in the runtime configuration. Configuration · Export script
We replayed both classifiers on 1,032 views of 344 images from six collections or volumes. Every binary proposal and every three-way action agreed with its PyTorch reference. The largest absolute split-score difference was 2.8e-06. A separate installation using only the inference dependencies also ran both command modes and tested image orientation, transparency and multi-frame rejection. Results by collection and runtime versions · Verification script
Both classifiers use 131 whole-image and 16 spread examples from 46 accession families, with equal total weight per class and equal family weight within class. Nineteen ambiguous examples were excluded from fitting. The ONNX conversion combines the two readouts and the encoder into a single graph. The original PyTorch probe, training references and image provenance are available in Folio Spread Bench. Training guide · DINOv2-Small checkpoint
The DINOv2 weights, fitted heads and scripts use Apache-2.0. The sample photograph of Illustrated book, accession JIB174.18, is a CC0 Open Access image from The Metropolitan Museum of Art, Gift of Lincoln Kirstein, 1959. Museum object record · License · Credits and changes
- Downloads last month
- 39
Model tree for foliokestrel/folio-page-layout
Base model
facebook/dinov2-small