feat(ocr): migrer l'OCR de docTR (PyTorch) vers OnnxTR (ONNX Runtime)
OnnxTR exécute les MÊMES modèles que docTR (db_resnet50 + crnn_vgg16_bn) sur ONNX Runtime, sans PyTorch. Corrige le crash torch/oneDNN « could not create a primitive » sur CPU contraint (VM 2 cœurs collaborateur : OCR scan impossible → quarantaine). Qualité identique validée empiriquement (CER 0,10-0,23 % vs docTR, 2 validations indépendantes Claude+Qwen), OCR ~2-3× plus rapide CPU. - core : import OnnxTR, _get_ocr_model(), _OCR_AVAILABLE, boucle OCR inchangée (API miroir) ; ONNXTR_CACHE_DIR pour le frozen ; bandeau de logs ENV au démarrage (OS, CPU+AVX, cœurs, RAM, versions, providers) pour retours terrain auto-suffisants. - 3 .spec : embarquent les poids ONNX OnnxTR (fail-closed) + hiddenimports onnxtr. - requirements : onnxtr[cpu] (python-doctr conservé transitoirement). - inclut le correctif quarantaine-visible du runner (GO Qwen). Tests : test_ocr_onnxtr.py (RED→GREEN), 95 unit passed, e2e scan client OK (OCR 5/5, PDF produit, plus de crash). Retrait torch du frozen + rebuild Windows = étapes suivantes (gates Dom). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -50,6 +50,25 @@ for relative_path in [
|
||||
if entry is not None:
|
||||
datas.append(entry)
|
||||
|
||||
onnxtr_cache_dir = Path(os.environ.get("ONNXTR_CACHE_DIR", Path.home() / ".cache" / "onnxtr"))
|
||||
required_onnxtr_weights = [
|
||||
"db_resnet50-69ba0015.onnx",
|
||||
"crnn_vgg16_bn-743599aa.onnx",
|
||||
]
|
||||
missing_onnxtr_weights = []
|
||||
for filename in required_onnxtr_weights:
|
||||
src = onnxtr_cache_dir / "models" / filename
|
||||
if src.exists():
|
||||
datas.append((str(src), "models/onnxtr/models"))
|
||||
else:
|
||||
missing_onnxtr_weights.append(str(src))
|
||||
if missing_onnxtr_weights:
|
||||
raise FileNotFoundError(
|
||||
"Poids OCR OnnxTR manquants pour le build frozen : "
|
||||
+ ", ".join(missing_onnxtr_weights)
|
||||
+ ". Précharger OnnxTR (lancer une OCR une fois) ou définir ONNXTR_CACHE_DIR avant PyInstaller."
|
||||
)
|
||||
|
||||
|
||||
hiddenimports = [
|
||||
"anonymizer_core_refactored_onnx",
|
||||
@@ -71,6 +90,14 @@ hiddenimports = [
|
||||
"doctr.models",
|
||||
"doctr.models.detection",
|
||||
"doctr.models.recognition",
|
||||
# OCR OnnxTR (remplace docTR — ONNX Runtime, sans torch)
|
||||
"onnxtr",
|
||||
"onnxtr.io",
|
||||
"onnxtr.models",
|
||||
"onnxtr.models.detection",
|
||||
"onnxtr.models.recognition",
|
||||
"onnxtr.utils",
|
||||
"onnxtr.utils.data",
|
||||
"cv2",
|
||||
"torchvision",
|
||||
"edsnlp",
|
||||
|
||||
Reference in New Issue
Block a user