Skip to content

Commit b35402c

Browse files
committed
feat(coral-tpu): add Docker EdgeTPU compiler + hardened Windows deploy
- Add docker/Dockerfile: linux/amd64 image with edgetpu_compiler + ultralytics Converts yolo26n.pt → TFLite INT8 → yolo26n_int8_edgetpu.tflite - Add docker/compile.sh: one-shot runner that mounts models/ as output - Add docker/docker-compose.yml: alternative Compose-based runner - Add docker/README.md: full instructions for compile, commit, and use - Rewrite deploy.bat (Option A — no pycoral): * Remove vestigial install_pycoral.py step (detect.py uses ai-edge-litert directly) * Check for pre-compiled yolo26n_edgetpu.tflite from git repo * Falls back to SSD MobileNet download if YOLO model not yet compiled * Cleaner UAC handling with unique temp dir names to prevent collisions * Informational Python version check (not blocking — 3.9-3.13 all work) - Update requirements.txt: clarify no pycoral dependency, document libedgetpu - Update models/README.md: Docker compile workflow + expected output files
1 parent c575193 commit b35402c

File tree

7 files changed

+435
-95
lines changed

7 files changed

+435
-95
lines changed
Lines changed: 134 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,216 @@
11
@echo off
2-
REM deploy.bat — Native local bootstrapper for Coral TPU Detection Skill (Windows)
2+
REM deploy.bat — Coral TPU Detection Skill installer for Windows
33
REM
4-
REM Builds a local Python virtual environment and installs the Google Coral Edge TPU
5-
REM natively on the host OS. Safely triggers UAC elevation for driver installation.
4+
REM What this does:
5+
REM 1. Downloads + installs the Edge TPU runtime (edgetpu.dll) via UAC
6+
REM 2. Creates a Python virtual environment (Python 3.9–3.11 recommended)
7+
REM 3. Installs ai-edge-litert and image processing deps
8+
REM 4. Verifies the compiled yolo26n_edgetpu.tflite model is present
9+
REM 5. Probes for an Edge TPU device
10+
REM
11+
REM Note: pycoral is NOT used. detect.py uses ai-edge-litert directly,
12+
REM which supports Python 3.9–3.13 and does not require pycoral.
613
REM
714
REM Exit codes:
8-
REM 0 = success
9-
REM 1 = fatal error (Python/pip not found or UAC denied)
10-
REM 2 = partial success (no TPU detected, will use CPU fallback)
15+
REM 0 = success (TPU detected and ready)
16+
REM 1 = fatal error
17+
REM 2 = partial success (no TPU detected, CPU fallback available)
1118

1219
setlocal enabledelayedexpansion
1320

1421
set "SKILL_DIR=%~dp0"
1522
set "LOG_PREFIX=[coral-tpu-deploy]"
1623

17-
REM Ensure we run inside the correct folder
24+
REM Ensure we run inside the skill folder
1825
cd /d "%SKILL_DIR%"
1926

2027
echo %LOG_PREFIX% Platform: Windows 1>&2
21-
echo {"event": "progress", "stage": "platform", "message": "Windows native environment detected"}
28+
echo {"event": "progress", "stage": "platform", "message": "Windows installer starting..."}
2229

23-
REM ─── Step 1: Install Native OS TPU Drivers (UAC Promoted) ───────────────
30+
REM ─── Step 1: Edge TPU Runtime (UAC elevated install) ─────────────────────────
31+
REM Download the official Google Edge TPU runtime for Windows and install it.
32+
REM This places edgetpu.dll into C:\Windows\System32 (requires admin rights).
2433

25-
echo %LOG_PREFIX% Downloading Google official x64 Windows installer... 1>&2
34+
echo %LOG_PREFIX% Downloading Edge TPU runtime... 1>&2
35+
echo {"event": "progress", "stage": "platform", "message": "Downloading Google Edge TPU runtime (edgetpu.dll)..."}
2636

27-
set "TMP_DIR=%TEMP%\coral_tpu_install"
28-
if not exist "%TMP_DIR%" mkdir "%TMP_DIR%"
37+
set "TMP_DIR=%TEMP%\coral_tpu_install_%RANDOM%"
38+
mkdir "%TMP_DIR%"
2939
cd /d "%TMP_DIR%"
3040

31-
powershell -Command "Invoke-WebRequest -Uri 'https://github.com/google-coral/libedgetpu/releases/download/release-grouper/edgetpu_runtime_20221024.zip' -OutFile 'edgetpu_runtime_20221024.zip'"
41+
powershell -NoProfile -Command ^
42+
"Invoke-WebRequest -Uri 'https://github.com/google-coral/libedgetpu/releases/download/release-grouper/edgetpu_runtime_20221024.zip' -OutFile 'edgetpu_runtime_20221024.zip' -UseBasicParsing"
3243
if %errorlevel% neq 0 (
33-
echo %LOG_PREFIX% ERROR: Failed to download Edge TPU runtime. 1>&2
44+
echo %LOG_PREFIX% ERROR: Failed to download Edge TPU runtime. Check internet connectivity. 1>&2
45+
echo {"event": "error", "stage": "platform", "message": "Download failed — check internet connectivity"}
46+
cd /d "%SKILL_DIR%"
47+
rmdir /S /Q "%TMP_DIR%" 2>nul
3448
exit /b 1
3549
)
3650

37-
powershell -Command "Expand-Archive -Path 'edgetpu_runtime_20221024.zip' -DestinationPath '.' -Force"
51+
powershell -NoProfile -Command ^
52+
"Expand-Archive -Path 'edgetpu_runtime_20221024.zip' -DestinationPath '.' -Force"
3853
cd edgetpu_runtime
3954

4055
echo %LOG_PREFIX% Prompting for Administrator rights to install drivers... 1>&2
41-
echo {"event": "progress", "stage": "platform", "message": "A separate UAC prompt and blue terminal will appear. Please approve it."}
42-
echo {"event": "progress", "stage": "platform", "message": "Waiting for Google install.bat to finish..."}
56+
echo {"event": "progress", "stage": "platform", "message": "A UAC prompt will appear. Approve it to install edgetpu.dll system-wide."}
4357

44-
REM Start the official install script elevated. Wait for it to finish.
45-
powershell -Command "Start-Process -FilePath 'cmd.exe' -ArgumentList '/c', 'install.bat < nul' -Verb RunAs -Wait"
58+
REM Run install.bat elevated and wait for it to complete.
59+
REM The '<nul' suppresses the clock-speed interactive prompt (uses the default: standard).
60+
powershell -NoProfile -Command ^
61+
"Start-Process -FilePath 'cmd.exe' -ArgumentList '/c install.bat <nul' -Verb RunAs -Wait"
4662

4763
if %errorlevel% neq 0 (
4864
echo.
49-
echo [MANUAL SETUP REQUIRED] UAC prompt was skipped or user aborted.
50-
echo Please execute the following fragile instructions manually in an Administrator console:
65+
echo [MANUAL SETUP REQUIRED]
66+
echo The UAC prompt was skipped or the install was cancelled.
67+
echo.
68+
echo To install manually, open an Administrator Command Prompt and run:
5169
echo.
52-
echo powershell -Command "Invoke-WebRequest -Uri 'https://github.com/google-coral/libedgetpu/releases/download/release-grouper/edgetpu_runtime_20221024.zip' -OutFile 'edgetpu_runtime_20221024.zip'"
53-
echo powershell -Command "Expand-Archive -Path 'edgetpu_runtime_20221024.zip' -DestinationPath '.'"
54-
echo cd edgetpu_runtime
55-
echo install.bat
70+
echo cd %TMP_DIR%\edgetpu_runtime
71+
echo install.bat
5672
echo.
57-
echo Once completed, re-run this deployment.
58-
echo {"event": "error", "stage": "platform", "message": "Manual OS setup required (UAC skipped)"}
73+
echo Then re-run this deployment script.
74+
echo {"event": "error", "stage": "platform", "message": "UAC install cancelled — manual setup required (see console)"}
5975
cd /d "%SKILL_DIR%"
60-
rmdir /S /Q "%TMP_DIR%"
76+
rmdir /S /Q "%TMP_DIR%" 2>nul
6177
exit /b 1
6278
)
6379

6480
cd /d "%SKILL_DIR%"
65-
rmdir /S /Q "%TMP_DIR%"
66-
67-
REM ─── Step 2: Ensure Python 3 ──────────────────────────────────────────────
68-
69-
set "PYTHON_CMD=python"
70-
python --version >nul 2>&1
71-
if %errorlevel% neq 0 (
72-
python3 --version >nul 2>&1
73-
if !errorlevel! equ 0 (
74-
set "PYTHON_CMD=python3"
75-
) else (
76-
echo %LOG_PREFIX% ERROR: Python not found. 1>&2
77-
echo {"event": "error", "stage": "python", "message": "Python not found"}
78-
exit /b 1
81+
rmdir /S /Q "%TMP_DIR%" 2>nul
82+
echo %LOG_PREFIX% Edge TPU runtime installed. 1>&2
83+
echo {"event": "progress", "stage": "platform", "message": "Edge TPU runtime installed successfully."}
84+
85+
REM ─── Step 2: Find Python ─────────────────────────────────────────────────────
86+
REM ai-edge-litert supports Python 3.9–3.13. We prefer the system default.
87+
REM If only Python 3.12+ is available, it still works (no pycoral needed).
88+
89+
set "PYTHON_CMD="
90+
91+
REM Try common Python launchers in preference order
92+
for %%P in (python python3 py) do (
93+
if not defined PYTHON_CMD (
94+
%%P --version >nul 2>&1
95+
if !errorlevel! equ 0 (
96+
set "PYTHON_CMD=%%P"
97+
)
7998
)
8099
)
81100

82-
echo %LOG_PREFIX% Using Python: !PYTHON_CMD! 1>&2
101+
if not defined PYTHON_CMD (
102+
echo %LOG_PREFIX% ERROR: Python not found on PATH. 1>&2
103+
echo {"event": "error", "stage": "python", "message": "Python not found — install Python 3.9-3.11 from python.org and re-run"}
104+
exit /b 1
105+
)
83106

84-
REM ─── Step 3: Create Virtual Environment ───────────────────────────────────
107+
REM Get Python version for info only (not blocking — ai-edge-litert works 3.9-3.13)
108+
for /f "tokens=2" %%V in ('!PYTHON_CMD! --version 2^>^&1') do set "PY_VERSION=%%V"
109+
echo %LOG_PREFIX% Python version: !PY_VERSION! 1>&2
110+
echo {"event": "progress", "stage": "python", "message": "Using Python !PY_VERSION!"}
111+
112+
REM ─── Step 3: Create virtual environment ──────────────────────────────────────
85113

86114
set "VENV_DIR=%SKILL_DIR%venv"
87-
echo %LOG_PREFIX% Setting up virtual environment in %VENV_DIR%... 1>&2
115+
echo %LOG_PREFIX% Creating virtual environment at %VENV_DIR%... 1>&2
88116
echo {"event": "progress", "stage": "build", "message": "Creating Python virtual environment..."}
89117

90118
!PYTHON_CMD! -m venv "%VENV_DIR%"
91119

92120
if not exist "%VENV_DIR%\Scripts\python.exe" (
93121
echo %LOG_PREFIX% ERROR: Failed to create virtual environment. 1>&2
94-
echo {"event": "error", "stage": "build", "message": "Failed to create venv"}
122+
echo {"event": "error", "stage": "build", "message": "venv creation failed"}
95123
exit /b 1
96124
)
97125

98-
REM ─── Step 4: Install PyCoral & Dependencies ───────────────────────────────
99-
100-
echo %LOG_PREFIX% Installing Python dependencies (including pycoral)... 1>&2
101-
echo {"event": "progress", "stage": "build", "message": "Fetching pycoral specific wheels..."}
126+
REM ─── Step 4: Install Python dependencies ─────────────────────────────────────
127+
REM ai-edge-litert: LiteRT runtime with Edge TPU delegate support (Python 3.9-3.13)
128+
REM numpy + Pillow: image processing
102129

103-
"%VENV_DIR%\Scripts\python.exe" -m pip install --upgrade pip >nul 2>&1
130+
echo %LOG_PREFIX% Upgrading pip... 1>&2
131+
"%VENV_DIR%\Scripts\python.exe" -m pip install --upgrade pip --quiet
104132

105-
"%VENV_DIR%\Scripts\python.exe" "%SKILL_DIR%scripts\install_pycoral.py"
106-
if %errorlevel% neq 0 (
107-
echo %LOG_PREFIX% WARNING: pycoral install script failed. 1>&2
108-
)
133+
echo %LOG_PREFIX% Installing dependencies (ai-edge-litert, numpy, Pillow)... 1>&2
134+
echo {"event": "progress", "stage": "build", "message": "Installing ai-edge-litert and image processing libraries..."}
109135

110-
"%VENV_DIR%\Scripts\python.exe" -m pip install -r "%SKILL_DIR%requirements.txt"
136+
"%VENV_DIR%\Scripts\python.exe" -m pip install -r "%SKILL_DIR%requirements.txt" --quiet
111137
if %errorlevel% neq 0 (
112-
echo %LOG_PREFIX% ERROR: Failed to install Python dependencies. 1>&2
113-
echo {"event": "error", "stage": "build", "message": "pip install failed"}
138+
echo %LOG_PREFIX% ERROR: pip install failed. 1>&2
139+
echo {"event": "error", "stage": "build", "message": "pip install requirements.txt failed"}
114140
exit /b 1
115141
)
116142

117-
echo %LOG_PREFIX% Dependencies installed successfully. 1>&2
143+
echo %LOG_PREFIX% Dependencies installed. 1>&2
144+
echo {"event": "progress", "stage": "build", "message": "Python dependencies installed successfully."}
118145

119-
REM ─── Step 5: Download Pre-compiled Models ──────────────────────────────────
146+
REM ─── Step 5: Verify compiled EdgeTPU model ────────────────────────────────────
147+
REM The yolo26n_edgetpu.tflite is pre-compiled via docker/compile.sh and committed
148+
REM to the git repository. deploy.bat does NOT compile it — that requires Linux.
120149

121-
echo %LOG_PREFIX% Downloading Edge TPU models... 1>&2
122-
echo {"event": "progress", "stage": "build", "message": "Downloading Edge TPU models..."}
150+
echo %LOG_PREFIX% Checking for compiled EdgeTPU model... 1>&2
123151

124-
if not exist "%SKILL_DIR%models" mkdir "%SKILL_DIR%models"
125-
cd /d "%SKILL_DIR%models"
152+
set "MODEL_FOUND=false"
153+
set "MODEL_FILE="
126154

127-
powershell -Command "Invoke-WebRequest -Uri 'https://github.com/google-coral/edgetpu/raw/master/test_data/ssd_mobilenet_v2_coco_quant_postprocess.tflite' -OutFile 'ssd_mobilenet_v2_coco_quant_postprocess.tflite'"
128-
powershell -Command "Invoke-WebRequest -Uri 'https://github.com/google-coral/edgetpu/raw/master/test_data/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite' -OutFile 'ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite'"
155+
REM Accept either naming convention from edgetpu_compiler output
156+
for %%M in (
157+
"%SKILL_DIR%models\yolo26n_int8_edgetpu.tflite"
158+
"%SKILL_DIR%models\yolo26n_edgetpu.tflite"
159+
"%SKILL_DIR%models\yolo26n_320_edgetpu.tflite"
160+
) do (
161+
if exist %%M (
162+
set "MODEL_FOUND=true"
163+
set "MODEL_FILE=%%~M"
164+
)
165+
)
129166

130-
cd /d "%SKILL_DIR%"
167+
if "!MODEL_FOUND!"=="false" (
168+
echo %LOG_PREFIX% WARNING: No pre-compiled EdgeTPU model found in models\. 1>&2
169+
echo {"event": "progress", "stage": "model", "message": "No EdgeTPU model found — will fall back to CPU inference (SSD MobileNet)"}
170+
171+
REM Download SSD MobileNet as a CPU fallback so the skill is functional immediately
172+
echo %LOG_PREFIX% Downloading SSD MobileNet CPU fallback model... 1>&2
173+
if not exist "%SKILL_DIR%models" mkdir "%SKILL_DIR%models"
174+
175+
powershell -NoProfile -Command ^
176+
"Invoke-WebRequest -Uri 'https://github.com/google-coral/edgetpu/raw/master/test_data/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite' -OutFile '%SKILL_DIR%models\ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite' -UseBasicParsing" 2>nul
177+
powershell -NoProfile -Command ^
178+
"Invoke-WebRequest -Uri 'https://github.com/google-coral/edgetpu/raw/master/test_data/ssd_mobilenet_v2_coco_quant_postprocess.tflite' -OutFile '%SKILL_DIR%models\ssd_mobilenet_v2_coco_quant_postprocess.tflite' -UseBasicParsing" 2>nul
179+
180+
echo {"event": "progress", "stage": "model", "message": "SSD MobileNet fallback downloaded. For YOLO 2026, run docker/compile.sh on Linux or macOS."}
181+
) else (
182+
echo %LOG_PREFIX% Found model: !MODEL_FILE! 1>&2
183+
echo {"event": "progress", "stage": "model", "message": "Edge TPU model ready: yolo26n_edgetpu.tflite"}
184+
)
131185

132-
REM ─── Step 6: Probe for Edge TPU devices ────────────────────────────────────
186+
REM ─── Step 6: Probe for Edge TPU devices ──────────────────────────────────────
133187

134-
echo %LOG_PREFIX% Probing for Edge TPU devices natively... 1>&2
135-
echo {"event": "progress", "stage": "probe", "message": "Checking for physical Edge TPU..."}
188+
echo %LOG_PREFIX% Probing for Edge TPU devices... 1>&2
189+
echo {"event": "progress", "stage": "probe", "message": "Checking for Coral USB Accelerator..."}
136190

137191
set "TPU_FOUND=false"
138-
set "TPU_COUNT=?"
192+
set "PROBE_JSON="
139193

140194
for /f "delims=" %%I in ('"%VENV_DIR%\Scripts\python.exe" "%SKILL_DIR%scripts\tpu_probe.py" 2^>nul') do (
141-
set "PROBE_OUTPUT=%%I"
195+
set "PROBE_JSON=%%I"
142196
)
143197

144-
echo !PROBE_OUTPUT! | findstr /C:"\"available\": true" >nul
198+
echo !PROBE_JSON! | findstr /C:"\"available\": true" >nul 2>&1
145199
if %errorlevel% equ 0 (
146200
set "TPU_FOUND=true"
147-
REM Approximate counts natively
148-
echo {"event": "progress", "stage": "probe", "message": "Edge TPU device natively registered"}
201+
echo %LOG_PREFIX% Edge TPU detected. 1>&2
202+
echo {"event": "progress", "stage": "probe", "message": "Coral USB Accelerator detected and ready."}
149203
) else (
150-
echo {"event": "progress", "stage": "probe", "message": "No Edge TPU detected -- CPU fallback available"}
204+
echo %LOG_PREFIX% No Edge TPU detected (device may not be plugged in). 1>&2
205+
echo {"event": "progress", "stage": "probe", "message": "No Edge TPU detected. Plug in the Coral USB Accelerator and restart the skill."}
151206
)
152207

153-
REM ─── Step 7: Complete ──────────────────────────────────────────────────────
208+
REM ─── Step 7: Done ────────────────────────────────────────────────────────────
154209

155210
if "!TPU_FOUND!"=="true" (
156-
echo {"event": "complete", "status": "success", "tpu_found": true, "message": "Native Coral TPU skill installed -- Edge TPU ready"}
211+
echo {"event": "complete", "status": "success", "tpu_found": true, "message": "Coral TPU skill installed and Edge TPU is ready."}
157212
exit /b 0
158213
) else (
159-
echo {"event": "complete", "status": "partial", "tpu_found": false, "message": "Native Coral TPU skill installed -- no TPU detected (CPU fallback)"}
214+
echo {"event": "complete", "status": "partial", "tpu_found": false, "message": "Coral TPU skill installed. Plug in your Coral USB Accelerator to enable hardware acceleration."}
160215
exit /b 2
161216
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# syntax=docker/dockerfile:1
2+
# ─────────────────────────────────────────────────────────────────────────────
3+
# Coral Edge TPU Model Compiler
4+
#
5+
# Converts YOLO 2026 nano (.pt) → TFLite INT8 → Edge TPU (.tflite)
6+
#
7+
# IMPORTANT: Must run on linux/amd64. edgetpu_compiler only exists for
8+
# x86_64 Linux. On Apple Silicon or Windows, use:
9+
# docker run --platform linux/amd64 ...
10+
# ─────────────────────────────────────────────────────────────────────────────
11+
12+
FROM --platform=linux/amd64 python:3.11-slim
13+
14+
LABEL maintainer="Aegis-AI / DeepCamera"
15+
LABEL description="Compiles YOLO 2026 nano to Google Coral Edge TPU .tflite"
16+
17+
# ── System deps ───────────────────────────────────────────────────────────────
18+
RUN apt-get update && apt-get install -y --no-install-recommends \
19+
curl \
20+
gnupg \
21+
apt-transport-https \
22+
ca-certificates \
23+
libgl1 \
24+
libglib2.0-0 \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
# ── Google Coral edgetpu_compiler (x86_64 Debian package) ────────────────────
28+
# Official Coral apt repository — edgetpu_compiler is only available here.
29+
RUN curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg \
30+
| gpg --dearmor -o /usr/share/keyrings/coral-edgetpu.gpg \
31+
&& echo "deb [signed-by=/usr/share/keyrings/coral-edgetpu.gpg] \
32+
https://packages.cloud.google.com/apt coral-edgetpu-stable main" \
33+
> /etc/apt/sources.list.d/coral-edgetpu.list \
34+
&& apt-get update \
35+
&& apt-get install -y --no-install-recommends edgetpu-compiler \
36+
&& rm -rf /var/lib/apt/lists/*
37+
38+
# ── Python deps ───────────────────────────────────────────────────────────────
39+
# ultralytics: YOLO export to TFLite INT8
40+
# tensorflow-cpu: required by ultralytics INT8 export (calibration + quantization)
41+
RUN pip install --no-cache-dir \
42+
"ultralytics>=8.3.0" \
43+
"tensorflow-cpu>=2.17.0,<3.0" \
44+
"numpy>=1.24.0,<2.0" \
45+
"Pillow>=10.0.0" \
46+
"onnx>=1.16.0"
47+
48+
# ── Copy compile script ───────────────────────────────────────────────────────
49+
WORKDIR /compile
50+
COPY scripts/compile_model.py /compile/compile_model.py
51+
52+
# ── Output volume ─────────────────────────────────────────────────────────────
53+
# Mount the skill's models/ directory here at runtime:
54+
# docker run -v /path/to/models:/compile/output ...
55+
VOLUME ["/compile/output"]
56+
57+
# ── Entrypoint ────────────────────────────────────────────────────────────────
58+
ENTRYPOINT ["python", "/compile/compile_model.py"]
59+
CMD ["--model", "yolo26n", "--size", "320", "--output", "/compile/output"]

0 commit comments

Comments
 (0)