import json,html
from pathlib import Path
R=Path(__file__).resolve().parents[1];O=R/'results/r94';d=json.loads((O/'results.json').read_text());rows=d['records'];assert len(rows)==23
summary=[]
for family,cat,label in [('gunduz','real','Gündüz real'),('gunduz','synthetic','Gündüz synthetic'),('khanom','r85','Khanom R85')]:
 a=[r for r in rows if (r['family'],r['category'])==(family,cat)];total=sum(r['references'] for r in a);v=[sum(r['scores'][name]['30']['0.5']['matched'] for r in a) for name in ('baseline','yolo','combined')];summary.append(f'<tr><td>{label} ({len(a)} cases)</td><td>{sum(r["yolo_count"] for r in a)}</td>'+''.join(f'<td>{n}/{total}</td>' for n in v)+'</tr>')
sections=[]
for r in rows:
 v=[r['scores'][name]['30']['0.5']['matched'] for name in ('baseline','yolo','combined')];sections.append(f'<section><h3>{html.escape(r["name"])}</h3><p>{r["references"]} references; YOLO emitted {r["yolo_count"]} masks. Top-30 baseline / YOLO / combined matches: {v[0]} / {v[1]} / {v[2]}. <a href="/{html.escape(r["source"])}">Source image</a> · <a href="{r["archive"]}">YOLO masks, scores and boxes</a></p><img src="{r["image"]}" alt="Source regions, baseline candidates, marine YOLO masks and combined candidates"></section>')
(O/'index.html').write_text('''<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>R94 diatom specialist transfer</title><style>body{font:16px/1.55 system-ui;max-width:1200px;margin:2em auto;padding:0 1em;color:#18342f}a{color:#006b59}img{max-width:100%}.box{background:#fff2d6;padding:1em}section{border-top:1px solid #ccc}td,th{padding:.4em;border:1px solid #bbc}table{border-collapse:collapse}</style><a href="/results/board.html">Research board</a> · <a href="/results/l81/">Box-refinement test</a><h1>R94: Does a marine diatom specialist transfer?</h1><p class="box">Twenty-three previously examined development cases; source specimens and model training data are not established independent. The YOLO model was trained for marine Pseudo-nitzschia chain images, so it encounters a substantially different domain here. These results do not measure severe real freshwater overlap or human-level performance, and do not rule out a suitably trained freshwater YOLO model.</p><p>Frozen YOLO11s-seg, model-card confidence 0.25, image size 640, internal NMS IoU 0.7, no reference-guided prompts. Compare the saved alternating SAM-point/Cellpose baseline, YOLO masks alone, and an alternating three-stream list. All outputs after YOLO's own internal filtering are retained; that filtering can suppress true overlapping instances. Other pipelines use different compute.</p><table><tr><th>Case group</th><th>YOLO masks</th><th>Baseline top 30</th><th>YOLO top 30</th><th>Combined top 30</th></tr>'''+''.join(summary)+'''</table><p>Scores are one-to-one matches to available source/visible regions at IoU ≥0.5. The marine model matched 2/16 Gündüz real references, 0/16 synthetic visible references and 1/9 Khanom references; adding its candidates did not change top-30 counts on these groups. Missing annotations mean unmatched YOLO masks are not necessarily false positives. Its default confidence and the model's chain-specific training may contribute to the mismatch.</p><p>Sources: <a href="https://huggingface.co/patcdaniel/pseudo-nitzschia-yolo11s-seg">marine specialist model</a> (MIT-tagged model card); <a href="https://www.kaggle.com/datasets/huseyingunduz/diatom-dataset">Gündüz diatoms</a>, CC BY-NC-SA 4.0; <a href="https://zenodo.org/records/21295927">Khanom diatoms</a>, CC BY 4.0. Local Academy synthetic backgrounds and software/model terms also apply.</p><p><a href="protocol.json">Frozen protocol</a> · <a href="results.json">All scores and mask provenance</a> · <a href="verify.log">Verification</a> · <a href="/research/R94.md">Research note</a></p><h2>Case comparisons</h2>'''+''.join(sections)+'</html>')
