检测侧:补扫没救回漏检,改成勾中口算卡时裁剪重读(312->321/330)
- scanflow._gap_bands/_gap_blocks:找出没被框盖住但有字的条带,裁出来补切一次 (OCR_GAP_SCAN=0 可关,一页最多 2 条);实测在 3 张漏检图上救回 0 道, 因为那 3 道不是空条带,而是框在、内容读歪(27+69 读成 77+69) - recognize_block 增加 crop_card 分支:勾中口算卡时裁出来重读,两版小题求并集 (宁多不漏;整页版吞行、裁剪版丢题,谁也说不全) - bench/verify_effect.py:同一份整页结果内比 page 与 page∪crop, 不跨调用比——腾讯切题两次调用本身就不完全一致 - bench/run.py --gap / --verify-cards;gold_expr.py --results - tests/test_gap_scan.py 5 例;卡片重读 2 例;179 单测 + 4 套冒烟全绿
This commit is contained in:
+5
-4
@@ -74,12 +74,13 @@ python bench/gold_expr.py --append # 追加成 report.md 第五节
|
||||
|
||||
`gold_expr.py` 会直接打印 Wilson 区间。为什么必须给区间:0 误判 + 83 道,95% 上界是 4.4%,读者没法据此相信「误判率 < 1%」;330 道时上界才落到 1.24%。反推:要把上界压到 1% 以内需要约 400 道,0.5% 以内约 800 道。同卷内的题不独立,真实区间比 Wilson 略宽——所以标 330 道也只敢说「1.5% 以内」。
|
||||
|
||||
漏检的 12 道分两类,都不是判题逻辑的错:
|
||||
**一个必须知道的事实:腾讯切题对同一张图的两次调用并不完全一致**(分段会变),所以跨两次 API 调用比「318 → 321」会把随机性当效果。要测某项改动的增益,只能用同一份整页结果比 `page` 与 `page∪crop`:`python bench/verify_effect.py`。
|
||||
|
||||
1. **极短算式被读错或被吞**(9 道):`0+0` 读成 `6+0`、`2+4`、`5×2`、`5×0`、`9×9`、`3×9`、`7×4`、`4+5`、`2+3+4`。密集口算卡里一行里有 4–5 道,框切得碎,单道容易丢。
|
||||
2. **整块没被切出来**(3 道):`27+69`、`92-(30+25)`、`4/5-2/5`。
|
||||
补扫(检测漏块)实测在 3 张漏检图上救回 **0 道**——那 3 道不是「没框」,而是「框在、内容读歪」:`27+69` 被读成 `77+69`,`4/5-2/5` 被整行吞掉。真正的解药是**卡片重读**(入库时把口算卡裁出来再读一次、两版求并集):同一份结果内 **312 → 321 / 330(96.4% → 97.3%)**。
|
||||
|
||||
竖式区那 6 道(`1.8+0.6` 到 `49×59`)已经在 `split_multi` 里修好——之前它们是一个 manual 块,现在拆成 6 道 calc 并逐道自算。这也说明:**漏检的瓶颈已经从「没法拆」挪到「OCR 没给出这块」**,再往上要动的是检测侧(裁剪重识别),不是解析侧。
|
||||
剩下的 9 道:`5×0`、`92-(30+25)`、`4/5-2/5`,以及 fa0885 的三道竖式(`68+27`/`80-49`/`75+17-43`)——都是 OCR 真没读出来,裁剪也救不了,属供应商能力边界。
|
||||
|
||||
竖式区那 6 道(`1.8+0.6` 到 `49×59`)已经在 `split_multi` 里修好——之前它们是一个 manual 块,现在拆成 6 道 calc 并逐道自算。
|
||||
|
||||
## 额度纪律(重要)
|
||||
|
||||
|
||||
+4
-1
@@ -95,6 +95,8 @@ def _wilson(k: int, n: int, z: float = 1.96) -> tuple[float, float]:
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--gold", default=str(GOLD))
|
||||
ap.add_argument("--results", default=str(RESULTS),
|
||||
help="换一份评测结果(比如开了卡片重读的 results.verified.jsonl)")
|
||||
ap.add_argument("--miss", action="store_true", help="列出没认出来的算式")
|
||||
ap.add_argument("--append", action="store_true", help="把结果追加成 report.md 的一节")
|
||||
args = ap.parse_args()
|
||||
@@ -104,7 +106,8 @@ def main() -> int:
|
||||
print(f"没有金标文件:{gold_path}")
|
||||
return 1
|
||||
gold = json.loads(gold_path.read_text(encoding="utf-8"))
|
||||
rows = {r["id"]: r for r in (json.loads(l) for l in RESULTS.open(encoding="utf-8") if l.strip())}
|
||||
res_path = Path(args.results)
|
||||
rows = {r["id"]: r for r in (json.loads(l) for l in res_path.open(encoding="utf-8") if l.strip())}
|
||||
|
||||
total = hit = wrong = miss = 0
|
||||
miss_list: list[tuple[str, str]] = []
|
||||
|
||||
+15
-2
@@ -75,7 +75,7 @@ def _to_block(i: int, q: dict) -> dict:
|
||||
return {"i": i, "box": q.get("box"), "stem": q["stem"],
|
||||
"judge_type": q.get("detected_as") or q.get("judge_type"),
|
||||
"options": q.get("options"), "page_answer": q.get("page_answer"),
|
||||
"subs": q.get("subs") or []}
|
||||
"subs": q.get("subs") or [], "from_gap": False}
|
||||
|
||||
|
||||
def main(argv=None) -> int:
|
||||
@@ -86,6 +86,10 @@ def main(argv=None) -> int:
|
||||
help="只用 OCR 缓存,缺的不发请求(额度用完后重算指标用)")
|
||||
ap.add_argument("--skip-done", action="store_true",
|
||||
help="跳过 results.jsonl 里已经跑成功过的图(省额度)")
|
||||
ap.add_argument("--gap", action="store_true",
|
||||
help="开启补扫(检测漏块,每张可能多 1–2 次调用)")
|
||||
ap.add_argument("--verify-cards", action="store_true",
|
||||
help="口算卡裁出来重读一次(每张多 1–3 次调用)")
|
||||
ap.add_argument("--out", default=str(RESULTS))
|
||||
args = ap.parse_args(argv)
|
||||
|
||||
@@ -121,7 +125,16 @@ def main(argv=None) -> int:
|
||||
if args.no_api:
|
||||
res = _detect_from_cache_only(data, fp.name)
|
||||
else:
|
||||
res = scanflow.detect(data, fp.name)
|
||||
res = scanflow.detect(data, fp.name, gap_scan=args.gap)
|
||||
if args.verify_cards and not args.no_api:
|
||||
# 口算卡在整页结果里偶尔会读歪(27+69 → 77+69):
|
||||
# 裁出这一块再读一次,题更多就信裁剪版(与入库时的逻辑一致)
|
||||
src = scanflow._img_path(res["draft_id"])
|
||||
for b in res.get("blocks") or []:
|
||||
if b.get("subs"):
|
||||
fixed = scanflow.recognize_block(src, b)
|
||||
if fixed.get("source") == "crop_card":
|
||||
b["subs"] = fixed["subs"]
|
||||
ok, code, blocks = True, "", res.get("blocks") or []
|
||||
except Exception as e: # noqa: BLE001
|
||||
ok, code, blocks = False, getattr(e, "code", type(e).__name__), []
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
"""一次性对照:同一份整页结果下,「卡片重读」能多救回几道金标。
|
||||
|
||||
为什么要写这个:腾讯切题对同一张图的两次调用并不完全一致(分段会变),
|
||||
跨两次调用比「318 → 321」会把随机性当成效果。这里只比同一份结果内的
|
||||
page 与 page∪crop 两个并集。
|
||||
"""
|
||||
import io
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from backend import scanflow # noqa: E402
|
||||
from bench.gold_expr import _norm_expr, _same # noqa: E402
|
||||
|
||||
GOLD = Path("bench/gold.json")
|
||||
RAW = Path("data/bench/raw")
|
||||
|
||||
|
||||
def _pairs(blocks):
|
||||
out = []
|
||||
for b in blocks:
|
||||
if b.get("subs"):
|
||||
out.extend((_norm_expr(s.get("stem")), str(s.get("answer") or "")) for s in b["subs"])
|
||||
elif b.get("stem"):
|
||||
out.append((_norm_expr(b.get("stem")), str(b.get("answer") or "")))
|
||||
return out
|
||||
|
||||
|
||||
def score(exprs, pairs):
|
||||
hit = 0
|
||||
for e in exprs:
|
||||
want = _norm_expr(e["t"])
|
||||
truth = str(e.get("a") or "").strip()
|
||||
exact = [p for p in pairs if p[0] == want]
|
||||
pref = [p for p in pairs if p[0].startswith(want) and p[0] != want]
|
||||
got = (exact or pref or [(None, None)])[0][1]
|
||||
if got and truth and (got.strip() == truth or _same(got, truth)):
|
||||
hit += 1
|
||||
return hit
|
||||
|
||||
|
||||
def main():
|
||||
gold = json.loads(GOLD.read_text(encoding="utf-8"))
|
||||
total = page_hit = merged_hit = crop_hit = 0
|
||||
for iid, spec in gold.items():
|
||||
if iid.startswith("_") or not isinstance(spec, dict):
|
||||
continue
|
||||
fp = RAW / f"{iid}.jpg"
|
||||
if not fp.exists():
|
||||
continue
|
||||
det = scanflow.detect(fp.read_bytes(), fp.name, gap_scan=False)
|
||||
src = scanflow._img_path(det["draft_id"])
|
||||
exprs = spec["exprs"]
|
||||
total += len(exprs)
|
||||
a = score(exprs, _pairs(det["blocks"]))
|
||||
page_hit += a
|
||||
merged, prefer = [], []
|
||||
for b in det["blocks"]:
|
||||
if b.get("subs"):
|
||||
m = scanflow.recognize_block(src, b) # 并集版
|
||||
merged.append(m)
|
||||
crop_only = [s for s in m["subs"]
|
||||
if s not in (b.get("subs") or [])]
|
||||
# 「裁剪版更多就整版换掉」的对照
|
||||
if len(m["subs"]) > len(b.get("subs") or []):
|
||||
prefer.append({**b, "subs": m["subs"]})
|
||||
else:
|
||||
prefer.append(b)
|
||||
else:
|
||||
merged.append(b)
|
||||
prefer.append(b)
|
||||
bb = score(exprs, _pairs(merged))
|
||||
cc = score(exprs, _pairs(prefer))
|
||||
merged_hit += bb
|
||||
crop_hit += cc
|
||||
if bb != a or cc != a:
|
||||
print(f"{iid} 整页 {a} / 并集 {bb} / 整版换 {cc}")
|
||||
print(f"合计 {total} 道:整页 {page_hit},并集 {merged_hit},整版换 {crop_hit}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user