forked from violetljj/blind-assist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_depth_fusion_benchmark.ps1
More file actions
262 lines (244 loc) · 12.1 KB
/
Copy pathrun_depth_fusion_benchmark.ps1
File metadata and controls
262 lines (244 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
param(
[string]$DatasetRoot = "artifacts.local\evidence\datasets\blindassist-evalset-20260527-impl",
[string]$DepthModelPath = "artifacts.local\downloads\depth-lab\exports\depth_anything_v2_small_fp32.tflite",
[string]$DepthModelAsset = "",
[ValidateSet("DepthFusion", "DepthFusionSweep")]
[string]$ComparisonMode = "DepthFusion",
[string]$DepthCloserIsLarger = "true",
[double]$DepthSamplePercentile = 0.50,
[double]$DepthInnerCropRatio = 1.0,
[string]$DepthLowerHalfOnly = "true",
[int]$DepthMinSamples = 4,
[double]$DepthMinLocalRange = 0.0,
[double]$DepthMinConfidence = 0.55,
[double]$DepthCriticalThreshold = 0.78,
[double]$DepthNearThreshold = 0.58,
[double]$DepthMidThreshold = 0.35,
[int]$ImageLimit = 100,
[int]$PureWarmup = 10,
[int]$PureRuns = 100,
[int]$AppRunsPerImage = 3,
[double]$MatchIouThreshold = 0.5,
[ValidateSet("current", "center_near_sensitive", "center_near_strict", "critical_sensitive", "side_near_sensitive")]
[string]$RiskConfig = "current",
[int]$DefaultRegressionSeconds = 90,
[switch]$SkipDefaultRegression,
[string]$AdbPath,
[string]$PythonPath = "E:\codex-tools\bin\blindassist-python.cmd",
[string]$GradleUserHome = "E:\codex-tools\projects\blindassist\state\gradle"
)
$ErrorActionPreference = "Stop"
function Resolve-RepoPath([string]$Path) {
if ([System.IO.Path]::IsPathRooted($Path)) {
return $Path
}
return (Join-Path $repoRoot $Path)
}
function Resolve-Adb([string]$RequestedPath) {
if ($RequestedPath) {
if (-not (Test-Path -LiteralPath $RequestedPath)) {
throw "ADB not found at $RequestedPath"
}
return (Resolve-Path -LiteralPath $RequestedPath).Path
}
$localAdb = Join-Path $repoRoot ".android-sdk\platform-tools\adb.exe"
if (Test-Path -LiteralPath $localAdb) {
return (Resolve-Path -LiteralPath $localAdb).Path
}
$command = Get-Command adb -ErrorAction SilentlyContinue
if ($command) {
return $command.Source
}
throw "ADB not found. Pass -AdbPath or install platform-tools."
}
function Invoke-Native {
param(
[string]$FilePath,
[string[]]$Arguments,
[string]$LogPath
)
$previousPreference = $ErrorActionPreference
$ErrorActionPreference = "Continue"
try {
$output = & $FilePath @Arguments 2>&1
$code = $LASTEXITCODE
} finally {
$ErrorActionPreference = $previousPreference
}
if ($LogPath) {
$output | Tee-Object -FilePath $LogPath
}
if ($code -ne 0) {
throw "$FilePath $($Arguments -join ' ') failed with exit code $code"
}
return $output
}
function Get-SingleDevice([string]$Adb) {
$output = Invoke-Native $Adb @("devices") $null
$devices = @(
$output |
Where-Object { $_ -match "^\S+\s+device$" } |
ForEach-Object { ($_ -split "\s+")[0] }
)
if ($devices.Count -ne 1) {
throw "Expected exactly one online device, found $($devices.Count). Raw adb devices output: $($output -join ' | ')"
}
return $devices[0]
}
function Convert-ToBoolString([string]$Value) {
$normalized = $Value.Trim().ToLowerInvariant()
if ($normalized -in @("true", "1", "yes", "y")) {
return "true"
}
if ($normalized -in @("false", "0", "no", "n")) {
return "false"
}
throw "Expected boolean value, got: $Value"
}
$repoRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..")).Path
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
$artifactRoot = Join-Path (Join-Path $repoRoot "artifacts.local\evidence\depth-fusion-benchmark") $timestamp
New-Item -ItemType Directory -Force -Path $artifactRoot | Out-Null
$python = Resolve-RepoPath $PythonPath
$yolo11n = Resolve-RepoPath "app\src\main\assets\yolo11n_fp16_320.tflite"
$depthModel = Resolve-RepoPath $DepthModelPath
$blindAssistEvalSet = Resolve-RepoPath $DatasetRoot
$resolvedGradleUserHome = Resolve-RepoPath $GradleUserHome
$apk = Resolve-RepoPath "app\build\outputs\apk\debug\app-debug.apk"
$aapt = Resolve-RepoPath ".android-sdk\build-tools\35.0.0\aapt.exe"
$adb = Resolve-Adb $AdbPath
$device = Get-SingleDevice $adb
if ([string]::IsNullOrWhiteSpace($DepthModelAsset)) {
$DepthModelAsset = "depth/$([System.IO.Path]::GetFileName($depthModel))"
}
$depthModelAssetName = [System.IO.Path]::GetFileName($DepthModelAsset)
$depthCloserIsLargerValue = Convert-ToBoolString $DepthCloserIsLarger
$depthLowerHalfOnlyValue = Convert-ToBoolString $DepthLowerHalfOnly
if (-not (Test-Path -LiteralPath $python)) {
throw "Python runtime not found: $python"
}
if (-not (Test-Path -LiteralPath $resolvedGradleUserHome -PathType Container)) {
throw "Gradle user home not found: $resolvedGradleUserHome"
}
if (-not (Test-Path -LiteralPath $yolo11n)) {
throw "yolo11n TFLite asset not found: $yolo11n"
}
if (-not (Test-Path -LiteralPath $depthModel)) {
throw "Depth TFLite candidate not found: $depthModel"
}
if (-not (Test-Path -LiteralPath (Join-Path $blindAssistEvalSet "manifest.jsonl"))) {
throw "BlindAssist evalset manifest not found: $(Join-Path $blindAssistEvalSet 'manifest.jsonl')"
}
if (-not (Test-Path -LiteralPath (Join-Path $blindAssistEvalSet "images\test"))) {
throw "BlindAssist evalset images/test directory not found: $(Join-Path $blindAssistEvalSet 'images\test')"
}
Push-Location $repoRoot
try {
$env:JAVA_HOME = (Resolve-Path ".\.jdk\jdk17.0.19_10").Path
$env:PATH = "$env:JAVA_HOME\bin;$((Resolve-Path '.\.android-sdk\platform-tools').Path);$env:PATH"
$env:GRADLE_USER_HOME = (Resolve-Path -LiteralPath $resolvedGradleUserHome).Path
New-Item -ItemType Directory -Force -Path ".\.android-home", ".\.kotlin-home" | Out-Null
$env:ANDROID_USER_HOME = (Resolve-Path ".\.android-home").Path
$env:KOTLIN_HOME = (Resolve-Path ".\.kotlin-home").Path
$env:GRADLE_OPTS = "-Dkotlin.compiler.execution.strategy=in-process"
Invoke-Native $python @("scripts\inspect_tflite.py") (Join-Path $artifactRoot "inspect-yolo11n.txt") | Out-Null
Invoke-Native $python @("scripts\inspect_depth_model.py", $DepthModelPath, "--json-output", (Join-Path $artifactRoot "inspect-depth-model.json")) (Join-Path $artifactRoot "inspect-depth-model.txt") | Out-Null
Invoke-Native $python @("scripts\smoke_depth_model.py", "--model", $DepthModelPath, "--dataset-root", $DatasetRoot, "--image-limit", "20", "--json-output", (Join-Path $artifactRoot "smoke-depth-model.json")) (Join-Path $artifactRoot "smoke-depth-model.txt") | Out-Null
Invoke-Native ".\gradlew.bat" @(
":app:assembleDebug",
":device-benchmark:assembleDebug",
"-PblindAssistEvalSetDir=$blindAssistEvalSet",
"-PdepthBenchmarkModelPath=$depthModel",
"-PdepthBenchmarkModelAssetName=$depthModelAssetName",
"--no-daemon",
"--console=plain"
) (Join-Path $artifactRoot "gradle-assemble.txt") | Out-Null
if (-not (Test-Path -LiteralPath $apk)) {
throw "Debug APK not found after build: $apk"
}
Invoke-Native $aapt @("list", $apk) (Join-Path $artifactRoot "main-apk-assets.txt") | Out-Null
$mainAssets = Get-Content -Path (Join-Path $artifactRoot "main-apk-assets.txt")
if ($mainAssets -notcontains "assets/yolo11n_fp16_320.tflite") {
throw "Default yolo11n asset is missing from the main debug APK."
}
if ($mainAssets -contains "assets/yolo26n_fp16_320.tflite") {
throw "yolo26n unexpectedly entered the main debug APK assets."
}
if ($mainAssets -contains "assets/depth/depth_anything_v2_small_fp32.tflite") {
throw "Depth model unexpectedly entered the main debug APK assets."
}
if ($mainAssets -contains "assets/$DepthModelAsset") {
throw "Depth model unexpectedly entered the main debug APK assets: assets/$DepthModelAsset"
}
Invoke-Native ".\gradlew.bat" @(
":device-benchmark:connectedDebugAndroidTest",
"-PblindAssistEvalSetDir=$blindAssistEvalSet",
"-PdepthBenchmarkModelPath=$depthModel",
"-PdepthBenchmarkModelAssetName=$depthModelAssetName",
"-Pandroid.testInstrumentationRunnerArguments.class=com.linnan.blindassist.benchmark.DetectorAbDeviceBenchmarkTest",
"-Pandroid.testInstrumentationRunnerArguments.datasetKind=BlindAssistEvalSet",
"-Pandroid.testInstrumentationRunnerArguments.comparisonMode=$ComparisonMode",
"-Pandroid.testInstrumentationRunnerArguments.depthModelAsset=$DepthModelAsset",
"-Pandroid.testInstrumentationRunnerArguments.depthCloserIsLarger=$depthCloserIsLargerValue",
"-Pandroid.testInstrumentationRunnerArguments.depthSamplePercentile=$DepthSamplePercentile",
"-Pandroid.testInstrumentationRunnerArguments.depthInnerCropRatio=$DepthInnerCropRatio",
"-Pandroid.testInstrumentationRunnerArguments.depthLowerHalfOnly=$depthLowerHalfOnlyValue",
"-Pandroid.testInstrumentationRunnerArguments.depthMinSamples=$DepthMinSamples",
"-Pandroid.testInstrumentationRunnerArguments.depthMinLocalRange=$DepthMinLocalRange",
"-Pandroid.testInstrumentationRunnerArguments.depthMinConfidence=$DepthMinConfidence",
"-Pandroid.testInstrumentationRunnerArguments.depthCriticalThreshold=$DepthCriticalThreshold",
"-Pandroid.testInstrumentationRunnerArguments.depthNearThreshold=$DepthNearThreshold",
"-Pandroid.testInstrumentationRunnerArguments.depthMidThreshold=$DepthMidThreshold",
"-Pandroid.testInstrumentationRunnerArguments.riskConfig=$RiskConfig",
"-Pandroid.testInstrumentationRunnerArguments.imageLimit=$ImageLimit",
"-Pandroid.testInstrumentationRunnerArguments.pureWarmup=$PureWarmup",
"-Pandroid.testInstrumentationRunnerArguments.pureRuns=$PureRuns",
"-Pandroid.testInstrumentationRunnerArguments.appRunsPerImage=$AppRunsPerImage",
"-Pandroid.testInstrumentationRunnerArguments.matchIouThreshold=$MatchIouThreshold",
"-Pandroid.injected.androidTest.leaveApksInstalledAfterRun=true",
"--no-daemon",
"--console=plain"
) (Join-Path $artifactRoot "connected-depth-fusion-benchmark.txt") | Out-Null
Invoke-Native $adb @("-s", $device, "logcat", "-d", "-s", "DetectorAbBenchmark", "BlindAssistPerf", "TfliteDepthEstimator") (Join-Path $artifactRoot "logcat-depth-fusion.txt") | Out-Null
$deviceArtifactRoot = "/sdcard/Android/data/com.linnan.blindassist/files/detector-ab-benchmark"
Invoke-Native $adb @("-s", $device, "pull", $deviceArtifactRoot, (Join-Path $artifactRoot "device-depth-fusion-benchmark")) (Join-Path $artifactRoot "adb-pull-depth-fusion.txt") | Out-Null
if (-not $SkipDefaultRegression) {
powershell -ExecutionPolicy Bypass -File .\scripts\run_device_regression.ps1 -SampleSeconds $DefaultRegressionSeconds 2>&1 |
Tee-Object -FilePath (Join-Path $artifactRoot "default-device-regression.txt")
if ($LASTEXITCODE -ne 0) {
throw "Default model device regression failed with exit code $LASTEXITCODE"
}
}
$summary = [ordered]@{
status = "passed"
timestamp = $timestamp
device = $device
artifactRoot = $artifactRoot
yolo11n = $yolo11n
depthModel = $depthModel
depthModelAsset = $DepthModelAsset
comparisonMode = $ComparisonMode
depthCloserIsLarger = $depthCloserIsLargerValue
depthSampling = [ordered]@{
samplePercentile = $DepthSamplePercentile
innerCropRatio = $DepthInnerCropRatio
lowerHalfOnly = $depthLowerHalfOnlyValue
minSamples = $DepthMinSamples
minLocalRange = $DepthMinLocalRange
minConfidence = $DepthMinConfidence
criticalThreshold = $DepthCriticalThreshold
nearThreshold = $DepthNearThreshold
midThreshold = $DepthMidThreshold
}
datasetKind = "BlindAssistEvalSet"
blindAssistEvalSet = $blindAssistEvalSet
matchIouThreshold = $MatchIouThreshold
appRunsPerImage = $AppRunsPerImage
riskConfig = $RiskConfig
defaultRegression = -not [bool]$SkipDefaultRegression
}
$summary | ConvertTo-Json -Depth 5 | Out-File -FilePath (Join-Path $artifactRoot "summary.json") -Encoding utf8
Write-Host "Depth fusion benchmark artifacts: $artifactRoot"
} finally {
Pop-Location
}