Download OCR_INDRA/make_contact_sheet.py from prosperious/ocr-projects-archive: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/prosperious/ocr-projects-archive/resolve/main/OCR_INDRA/make_contact_sheet.py
- Command line
-
hf download hf://prosperious/ocr-projects-archive/OCR_INDRA/make_contact_sheet.py
-
curl -L -o make_contact_sheet.py https://huggingface.co/prosperious/ocr-projects-archive/resolve/main/OCR_INDRA/make_contact_sheet.py
1.02 kB
| import json, re | |
| from pathlib import Path | |
| from PIL import Image, ImageDraw | |
| root = Path.home() / "ocr" | |
| repo = root / "OCR_INDRA" | |
| data = root / "ocr-deva-ft/data/chunks-v4/test" | |
| preds = repo / "results/stratified_1500/predictions_experiment1_all_models.jsonl" | |
| out = repo / "results/stratified_1500/error_contact_sheet.png" | |
| rows = [json.loads(s) for s in preds.open()] | |
| strip = lambda s: re.sub(r"\s+", "", s) | |
| bad = [r for r in rows if r["model"] == "Indra-FT" | |
| and not r["exact_match"] | |
| and strip(r["ground_truth"]) != strip(r["prediction"])][:10] | |
| w, h = 900, 165 | |
| sheet = Image.new("RGB", (w, h * len(bad)), "white") | |
| draw = ImageDraw.Draw(sheet) | |
| for i, r in enumerate(bad): | |
| im = Image.open(data / r["image"]).convert("RGB") | |
| im.thumbnail((880, 110)) | |
| y = i * h | |
| sheet.paste(im, (10, y)) | |
| draw.text((10, y + 116), "REF: " + r["ground_truth"], fill="black") | |
| draw.text((10, y + 138), "FT: " + r["prediction"], fill="blue") | |
| sheet.save(out) | |
| print("Saved:", out) | |
| print("Crops:", len(bad)) | |