Skip to content

Commit f8b6503

Browse files
artizclaude
andcommitted
wasm scan: log the layout region-label histogram
Diagnostic for the browser scanned path: console-log the per-page region labels after refinement, so it's visible whether the layout flagged any `table` region — a scanned table only fills when it does and the region's words are OCR'd (a known gap: prep_region_lines skips non-text labels, so table interiors currently carry no words for the matcher). Refs #157 Signed-off-by: artiz <artem.kustikov@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EY5KAiquN4YpVf2PXEQkVT
1 parent 195d18a commit f8b6503

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

crates/docling-wasm/src/scanned.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ use wasm_bindgen::prelude::*;
3333
use crate::ocr::{tensor_parts, RecSession};
3434
use crate::tableformer::TfSession;
3535

36+
#[wasm_bindgen]
37+
extern "C" {
38+
#[wasm_bindgen(js_namespace = console, js_name = log)]
39+
fn console_log(s: &str);
40+
}
41+
3642
#[wasm_bindgen]
3743
extern "C" {
3844
/// The JS-side layout session: a wrapper around an `ort.InferenceSession`
@@ -145,6 +151,19 @@ impl ScannedConverter {
145151
let regions = decode_layout(&logits, &boxes, q, c, page_w, page_h);
146152
let regions = refine_regions(regions, &[], page_w, page_h);
147153

154+
// Diagnostic: the region-label histogram, so it's visible (browser
155+
// console) whether the layout model flagged any `table` region on this
156+
// page — tables only render when it does (geometric or TableFormer).
157+
{
158+
let mut hist: std::collections::BTreeMap<&str, usize> =
159+
std::collections::BTreeMap::new();
160+
for r in &regions {
161+
*hist.entry(r.label).or_default() += 1;
162+
}
163+
let summary: Vec<String> = hist.iter().map(|(l, n)| format!("{l}×{n}")).collect();
164+
console_log(&format!("layout regions: {}", summary.join(", ")));
165+
}
166+
148167
// OCR the text regions (same gather/batch/decode as native ocr_page).
149168
let (bboxes, lines) = prep_region_lines(&img, &regions, scale);
150169
let mut texts = vec![String::new(); lines.len()];

0 commit comments

Comments
 (0)