|
1 | 1 | @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 |
3 | 3 | 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. |
6 | 13 | REM |
7 | 14 | 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) |
11 | 18 |
|
12 | 19 | setlocal enabledelayedexpansion |
13 | 20 |
|
14 | 21 | set "SKILL_DIR=%~dp0" |
15 | 22 | set "LOG_PREFIX=[coral-tpu-deploy]" |
16 | 23 |
|
17 | | -REM Ensure we run inside the correct folder |
| 24 | +REM Ensure we run inside the skill folder |
18 | 25 | cd /d "%SKILL_DIR%" |
19 | 26 |
|
20 | 27 | 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..."} |
22 | 29 |
|
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). |
24 | 33 |
|
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)..."} |
26 | 36 |
|
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%" |
29 | 39 | cd /d "%TMP_DIR%" |
30 | 40 |
|
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" |
32 | 43 | 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 |
34 | 48 | exit /b 1 |
35 | 49 | ) |
36 | 50 |
|
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" |
38 | 53 | cd edgetpu_runtime |
39 | 54 |
|
40 | 55 | 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."} |
43 | 57 |
|
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" |
46 | 62 |
|
47 | 63 | if %errorlevel% neq 0 ( |
48 | 64 | echo. |
49 | | - echo [91m[MANUAL SETUP REQUIRED][0m 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: |
51 | 69 | echo. |
52 | | - echo [96mpowershell -Command "Invoke-WebRequest -Uri 'https://github.com/google-coral/libedgetpu/releases/download/release-grouper/edgetpu_runtime_20221024.zip' -OutFile 'edgetpu_runtime_20221024.zip'"[0m |
53 | | - echo [96mpowershell -Command "Expand-Archive -Path 'edgetpu_runtime_20221024.zip' -DestinationPath '.'"[0m |
54 | | - echo [96mcd edgetpu_runtime[0m |
55 | | - echo [96minstall.bat[0m |
| 70 | + echo cd %TMP_DIR%\edgetpu_runtime |
| 71 | + echo install.bat |
56 | 72 | 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)"} |
59 | 75 | cd /d "%SKILL_DIR%" |
60 | | - rmdir /S /Q "%TMP_DIR%" |
| 76 | + rmdir /S /Q "%TMP_DIR%" 2>nul |
61 | 77 | exit /b 1 |
62 | 78 | ) |
63 | 79 |
|
64 | 80 | 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 | + ) |
79 | 98 | ) |
80 | 99 | ) |
81 | 100 |
|
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 | +) |
83 | 106 |
|
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 ────────────────────────────────────── |
85 | 113 |
|
86 | 114 | 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 |
88 | 116 | echo {"event": "progress", "stage": "build", "message": "Creating Python virtual environment..."} |
89 | 117 |
|
90 | 118 | !PYTHON_CMD! -m venv "%VENV_DIR%" |
91 | 119 |
|
92 | 120 | if not exist "%VENV_DIR%\Scripts\python.exe" ( |
93 | 121 | 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"} |
95 | 123 | exit /b 1 |
96 | 124 | ) |
97 | 125 |
|
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 |
102 | 129 |
|
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 |
104 | 132 |
|
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..."} |
109 | 135 |
|
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 |
111 | 137 | 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"} |
114 | 140 | exit /b 1 |
115 | 141 | ) |
116 | 142 |
|
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."} |
118 | 145 |
|
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. |
120 | 149 |
|
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 |
123 | 151 |
|
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=" |
126 | 154 |
|
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 | +) |
129 | 166 |
|
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 | +) |
131 | 185 |
|
132 | | -REM ─── Step 6: Probe for Edge TPU devices ──────────────────────────────────── |
| 186 | +REM ─── Step 6: Probe for Edge TPU devices ────────────────────────────────────── |
133 | 187 |
|
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..."} |
136 | 190 |
|
137 | 191 | set "TPU_FOUND=false" |
138 | | -set "TPU_COUNT=?" |
| 192 | +set "PROBE_JSON=" |
139 | 193 |
|
140 | 194 | 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" |
142 | 196 | ) |
143 | 197 |
|
144 | | -echo !PROBE_OUTPUT! | findstr /C:"\"available\": true" >nul |
| 198 | +echo !PROBE_JSON! | findstr /C:"\"available\": true" >nul 2>&1 |
145 | 199 | if %errorlevel% equ 0 ( |
146 | 200 | 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."} |
149 | 203 | ) 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."} |
151 | 206 | ) |
152 | 207 |
|
153 | | -REM ─── Step 7: Complete ────────────────────────────────────────────────────── |
| 208 | +REM ─── Step 7: Done ──────────────────────────────────────────────────────────── |
154 | 209 |
|
155 | 210 | 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."} |
157 | 212 | exit /b 0 |
158 | 213 | ) 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."} |
160 | 215 | exit /b 2 |
161 | 216 | ) |
0 commit comments