Add Custom OpenCV and ONNX Runtime Builds and OCR performance optimization - #57
Conversation
- delete OcrDigits.kt (HOG feature extraction + findNearest helpers) - remove kNearestModel parameter from DeviceOcr constructor - remove pfl/pure/far/lost/score/maxRecall methods (dead code since ONNX migration) - remove FixRects (only used by removed KNN digit pipeline)
- remove kNearestModel parameter from DeviceOcrHelper.ocrImage - stop loading KNN model in OcrQueueOcrImageTaskExecutor and OcrFromShareViewModel.startOcr
- drop kNearestModel() loaders, KNearestModelStatusDetail and status builder - remove knnModelFile path constant and its deletion in emergency mode - add LegacyKnnModelCleanUpTask to clean up leftover digits.knn.dat on devices that installed before the removal
- delete OcrDependencyKNearestModelStatusViewer (status card + ui state) - remove KNearest status cards from OcrNavEntry, OcrFromShare card and OcrDependenciesScreen - remove importKNearestModel and related state from OcrDependenciesScreenViewModel
- delete ocr_dependency_knn_model strings (app + shared composeResources, zh-rCN) - delete ic_knearest_model drawable
- OpenCV 5.0 removes ml (KNearest) and HOG from the main repo; both were already removed from this codebase, so no migration needed - usage limited to stable core/imgproc/imgcodecs/android APIs, verified by Android Studio build (no problems)
Database version jumped from 2 to 4 in 80139db; version 3 was never published, but the AutoMigration was generated against a fictional 3.json (enqueue_buffer with uri_type column) which crashes on real v2 databases (no such column: uri_type). Remove the AutoMigration and the spec; old databases now hit the existing fallbackToDestructiveMigration(dropAllTables = true) path and are rebuilt cleanly as v4.
Switch to the local maven repo (maven-local/) that overrides official onnxruntime 1.26.0 and opencv 5.0.0 with custom-built AARs. Parse dual-block model_info.json for the dependency status card instead of OnnxModelMetadata, disable graph optimization (NO_OPT) for the reduced-op runtime, and read INT32 model output directly.
Add setup-custom-maven action that downloads maven_repo.zip from the custom-lib-builds stable release tags (onnxruntime-1.26.0, opencv-5.0.0) into maven-local/, overriding official artifacts with identical GAV. Wire it into build_unstable, check, and connected-android-test workflows. No cache: stable tags are overwritten on publish (URL stable, content changes), so version-based cache keys would serve stale artifacts.
Compare .so sha256 between maven-local/ AARs and built APKs, guarding against silent fallback to official onnxruntime/opencv artifacts. Warnings go to annotations and the job summary; continue-on-error keeps artifact upload and release drafting unblocked.
Move the download/extract logic out of the composite action and the apksigner checks out of the workflow, so both are runnable and testable locally. setup-custom-maven and verify-apk-signing keep hard-fail semantics; verify-custom-libs remains soft-fail. Cleaned up shellcheck findings along the way.
- Previous commit was mislead, this commit actually just fixes it.
283375
left a comment
There was a problem hiding this comment.
Needs further investigations
Addresses PR #57 review: the device-derived parallelCount default and range now live in a dedicated OcrQueueParallelism object instead of the companion of the @serializable preferences class, keeping runtime strategy separate from the preferences schema. No behavior change.
Addresses PR #57 review: replace the byte-level checkModelAsset with verifyModelAsset, which creates a throwaway ORT session (validating the file itself and the custom build's op coverage) and cross-checks its metadata against model_info.json — version (semver-decoded), producer, domain, graph name, input/output names, and the custom metadata entries written by the exporter. All mismatches are collected into a single IllegalStateException surfaced on the dependency status card. The comparison logic lives in a pure collectMetadataMismatches function covered by JVM unit tests (8 cases); the removed modelVersion dead code is revived as onnxModelVersion and put to use.
- format report/history/log numbers with Locale.ROOT so decimal separators stay consistent across device locales - use a strict median over timed batches instead of the upper-middle element for even batch counts - read the parallel count once and reuse it for runningParallel, runBenchmark and history, instead of two independent reads - collapse preferences init into a single atomic state update - unify the running-state reset in a finally block across exit paths - poll cancellation between image decodes, which contain no suspension points - remove What-style comments; document why the report is not localized
|
/opencode review this pr |
|
I've reviewed the full diff (56 files) against SummarySolid, well-organized PR. The KNearest removal is clean (all call sites updated, no dangling references), the Issues1. Room 3→4 migration removal can destroy user data (medium, verify) — 2. CI never validates the real model asset against 3. Model verification doesn't run inference (low) — 4. 5. Double-tap race in 6. Soft-fail undermines the "hard-fail" intent (low) — 7. Nits
Positives
|

hammingDistanceis now allocation-free in image hash lookups, previous zip-based version caused severe GC pressure. Now queue throughput is roughly doubled