Support ai-edge-litert as TFLite runtime
tflite-runtime has no wheels for Python 3.12+. Google replaced it with ai-edge-litert (same API). detector.py now tries ai-edge-litert first, falls back to tflite-runtime for older Python versions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -54,12 +54,17 @@ class ObjectDetector:
|
|||||||
|
|
||||||
def _load_model(self):
|
def _load_model(self):
|
||||||
"""Load TFLite model and label map"""
|
"""Load TFLite model and label map"""
|
||||||
|
# Try ai-edge-litert (modern), then tflite-runtime (legacy)
|
||||||
|
try:
|
||||||
|
from ai_edge_litert import interpreter as tflite
|
||||||
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
import tflite_runtime.interpreter as tflite
|
import tflite_runtime.interpreter as tflite
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"tflite-runtime not installed. "
|
"No TFLite runtime found. Install one of:\n"
|
||||||
"Install with: pip install tflite-runtime"
|
" pip install ai-edge-litert (Python 3.12+)\n"
|
||||||
|
" pip install tflite-runtime (Python 3.9-3.11)"
|
||||||
)
|
)
|
||||||
|
|
||||||
if not self.model_path.exists():
|
if not self.model_path.exists():
|
||||||
|
|||||||
@@ -14,4 +14,5 @@ python-dotenv>=1.0.0
|
|||||||
httpx>=0.24.0
|
httpx>=0.24.0
|
||||||
|
|
||||||
# Object detection (installed separately by setup.sh)
|
# Object detection (installed separately by setup.sh)
|
||||||
# tflite-runtime>=2.14.0
|
# pip install ai-edge-litert (Python 3.12+)
|
||||||
|
# pip install tflite-runtime (Python 3.9-3.11)
|
||||||
|
|||||||
@@ -92,7 +92,9 @@ pip install -r requirements.txt
|
|||||||
|
|
||||||
# Install TFLite runtime for object detection
|
# Install TFLite runtime for object detection
|
||||||
echo_info "Installing TFLite runtime for object detection..."
|
echo_info "Installing TFLite runtime for object detection..."
|
||||||
pip install tflite-runtime 2>/dev/null || echo_warn "tflite-runtime not available for this platform (object detection will be disabled)"
|
pip install ai-edge-litert 2>/dev/null || \
|
||||||
|
pip install tflite-runtime 2>/dev/null || \
|
||||||
|
echo_warn "No TFLite runtime available for this platform (object detection will be disabled)"
|
||||||
|
|
||||||
# Generate SSL certificates if not present
|
# Generate SSL certificates if not present
|
||||||
if [ ! -f ssl/cert.pem ]; then
|
if [ ! -f ssl/cert.pem ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user