imgcli\cli_ocrbench.mbt
68.8% · 22 / 32 points · 52 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// `ocrbench` — 英文字符识别基准(S30 的可复算入口)。 - 3
/// - 4
/// 跑库里 36 类 × 3 档倍率 × 2 档退化 = 216 个样本,回准确率、clean/degraded 分档、 - 5
/// 逐字符命中与混淆对(按次数降序,最多 12 对)。 - 6
/// `--min` 给阈值(默认 0.85),不达标按普通失败处理(退出码 1),回执里同时带 `accuracy`。 - 7
fn cmd_ocrbench(flags : Flags) -> Out raise @types.ImageError { - 8●
let min_acc = flags.dbl("min", 0.85) - 9●
let report = @ocr.ocr_letter_bench() catch { - 10○
e => raise @types.image_error_from_load(e) - 11
} - 12
let per_char : Array[@json.Json] = [] - 13
for one in report.per_char { - 14●
per_char.push( - 15●
@json.Json::object({ - 16●
"label": jstr(one.label), - 17●
"hits": jnum(one.hits), - 18●
"total": jnum(one.total), - 19
}), - 20
) - 21
} - 22
let confusion : Array[@json.Json] = [] - 23
for one in report.confusion { - 24○
if confusion.length() >= 12 { - 25○
break - 26
} - 27○
confusion.push( - 28○
@json.Json::object({ - 29○
"expect": jstr(one.expect), - 30○
"got": jstr(one.got), - 31○
"count": jnum(one.count), - 32
}), - 33
) - 34
} - 35●
let out = result({ - 36●
"cases": jnum(report.cases), - 37●
"hits": jnum(report.hits), - 38●
"accuracy": q3(report.accuracy), - 39●
"clean_accuracy": q3(report.clean_accuracy), - 40●
"degraded_accuracy": q3(report.degraded_accuracy), - 41●
"min_accuracy": q3(min_acc), - 42●
"per_char": @json.Json::array(per_char), - 43●
"confusion": @json.Json::array(confusion), - 44
}) - 45
if report.accuracy < min_acc { - 46
// 不 raise:把 per_char / confusion 一起交给调用方,失败也有可读的回执 - 47●
out["ok"] = jbool(false) - 48●
out["code"] = jstr("ocr/accuracy_below_min") - 49●
out["exit_code"] = jnum(1) - 50
} - 51
out - 52
}