Migrate off pycoral to ai-edge-litert#2
Merged
Merged
Conversation
pycoral/tflite_runtime are abandoned upstream and only ever shipped cp39 wheels, which pinned this whole project to Python 3.9 and, downstream of that, to numpy 1.x (pycoral's compiled bindings are built against the numpy 1.x C ABI). Migrating to ai-edge-litert (Google's actively maintained LiteRT runtime, wheels through Python 3.14, no numpy ceiling) removes both constraints. - detector.py: rewritten to use ai_edge_litert.interpreter directly (Interpreter + load_delegate), reimplementing pycoral's small pure-Python surface area (input tensor resize/pad, output tensor parsing for SSD-style detection models, including the same 'legacy tensor order' fallback pycoral used for older model exports). Public API (DogDetector.__init__/.detect()) is unchanged, so camera_pipeline.py and dogwatch.py needed no changes. - Dockerfile: python:3.9-slim-bookworm -> python:3.12-slim-bookworm, ai-edge-litert==2.1.6 replacing the pycoral/tflite_runtime wheel URLs, numpy/opencv-python-headless/requests/paho-mqtt/shapely all bumped to current stable releases (no more version ceiling forcing them behind). - Verified locally: full amd64 Docker build succeeds; all modules import inside the container; ran the real ssd_mobilenet_v2_coco_quant_postprocess model (CPU/XNNPACK, since the Edge TPU delegate needs real hardware) against a known two-dog test photo and got two correct 93%-confidence dog detections with sane bounding boxes, confirming the reimplemented tensor parsing produces identical results to pycoral's. - Added tests/test_detector.py (8 tests) covering the tensor-parsing logic with fake interpreter objects, including both output-tensor-order branches pycoral supported. - requirements-test.txt and .github/workflows/ci.yml bumped to Python 3.12 and the same current dependency versions as the Dockerfile. - README: rewrote the pycoral-specific 'Known limitations' entries to describe the new ai-edge-litert + feranick/libedgetpu stack and its own (much smaller) residual risk. - .gitignore: add .ssh (homelab SSH credentials file, was untracked but unignored). NOT yet verified: the actual Edge TPU delegate against real Coral hardware (/dev/apex_0) — that requires the physical server and is the next step before merging to main.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
Owner
Author
Hardware verification: passed ✅Verified on the real Coral PCIe M.2 TPU (`/dev/apex_0`) via SSH to the homelab server:
Merging. |
VIDGuide
pushed a commit
that referenced
this pull request
Jul 12, 2026
…e of missed alerts User reported missed dog-at-fence alerts and suspected the ai-edge-litert migration (PR #2). Investigated live on the server: - Confirmed the Coral TPU, MQTT pipeline, and camera streams were all healthy — no infrastructure issue. - Used 5 real past-detection sample images (4 rear-east alert photos + 1 live fence-camera capture with a confirmed dog in frame) to test the actual production detector against real hardware. - All 5 samples showed weak (~0.20) or zero detection scores at the full frame — but a direct A/B test against the pre-migration pycoral/ tflite_runtime stack, run on the same hardware with the same samples, produced IDENTICAL scores and bounding boxes. This rules out the ai-edge-litert migration as the cause. - Root cause: ssd_mobilenet_v2's fixed 300x300 input resolution struggles with small/distant dogs in full uncropped wide-angle frames (confirmed: cropping the same images to the region containing the dog raised scores from 0.00 to 0.72-0.80). This is a pre-existing model limitation, not a regression — it just hadn't been exercised by dogs at this distance before, or was previously borderline-passing and tipped over by normal score jitter. - Actionable fix identified: the fence 'camera' config has no crop_roi set (unlike rear-east, which already uses one), which is the most direct lever to improve small-object detection sensitivity on that camera. Added: - samples/ (5 real images + README.md documenting ground truth, measured baseline scores, and the A/B test methodology) - tests/hardware_smoke_test.py: runs the real DogDetector against real Coral TPU hardware using these samples, comparing against tracked baseline scores to catch future regressions (vs. a prior naive version that would have falsely flagged all 5 known-weak samples as failures every run) - README: documented the smoke test, and flagged crop_roi as the recommended fix for the fence camera in the config reference table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces pycoral/tflite_runtime (abandoned upstream, cp39-only) with
ai-edge-litert (Google's actively maintained LiteRT runtime), removing the
Python 3.9 pin and the downstream numpy 1.x / opencv-python-headless 4.9.x
version ceiling it forced. See #1 for the full background on why this was
needed.
What changed
detector.pyrewritten againstai_edge_litert.interpreterdirectly —reimplements the small pure-Python surface area pycoral used to wrap
(input tensor resize/pad, output tensor parsing). Public API unchanged.
Dockerfile:python:3.9→python:3.12, current stable versions ofnumpy/opencv/requests/paho-mqtt/shapely (no more forced pins).
tests/test_detector.py(new, 8 tests) covering the tensor-parsing logic.Verified so far (this machine, no Coral hardware)
linux/amd64Docker build succeeds.ssd_mobilenet_v2_coco_quant_postprocessmodel (CPU/XNNPACKinterpreter, since the Edge TPU delegate needs real hardware) against a
known two-dog test photo — got two correct 93%-confidence dog detections
with correct bounding boxes, confirming the reimplemented tensor parsing
matches pycoral's behavior exactly.
ai-edge-litertpackage installed.Not yet verified
/dev/apex_0).This is the next step — will verify on the physical server before
merging.