Log track transitions and visitor matching decisions
This commit is contained in:
parent
8ec2452dcd
commit
f75ee629d1
|
|
@ -1,5 +1,5 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.it_screen.edgevision" android:versionCode="24" android:versionName="0.3.19">
|
||||
package="com.it_screen.edgevision" android:versionCode="25" android:versionName="0.3.20">
|
||||
<uses-sdk android:minSdkVersion="30" android:targetSdkVersion="34"/>
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-feature android:name="android.hardware.camera.any" android:required="true"/>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# EVAx10 Video analitics v0.3.19
|
||||
# EVAx10 Video analitics v0.3.20
|
||||
|
||||
A separate native Android experiment for consenting adult volunteers.
|
||||
Package `com.it_screen.edgevision`. The existing FaceAPI baseline is
|
||||
|
|
@ -10,10 +10,10 @@ installable as `com.it_screen.audiencepoc`.
|
|||
`./build.sh` builds the ARM64, API 30+ APK with the Windows Android SDK 35
|
||||
and JDK 17 via WSL. The script pins and verifies the upstream Maven AAR.
|
||||
Model assets load locally and are verified before ONNX Runtime session
|
||||
creation. The signed test build is `build/EVAx10-Video-analitics-0.3.19.apk`.
|
||||
creation. The signed test build is `build/EVAx10-Video-analitics-0.3.20.apk`.
|
||||
|
||||
```text
|
||||
adb install --no-incremental -r EVAx10-Video-analitics-0.3.19.apk
|
||||
adb install --no-incremental -r EVAx10-Video-analitics-0.3.20.apk
|
||||
adb shell am start -W -n com.it_screen.edgevision/.MainActivity
|
||||
adb logcat -s EdgeVision EdgeVisionBench
|
||||
```
|
||||
|
|
@ -96,7 +96,7 @@ or an Android low-memory signal is red.
|
|||
### Controlled Face Re-ID PoC
|
||||
|
||||
Build with `./build.sh --face-reid-poc`. Install
|
||||
`build/EVAx10-Video-analitics-0.3.19-Face-ReID-PoC.apk` as the separate package
|
||||
`build/EVAx10-Video-analitics-0.3.20-Face-ReID-PoC.apk` as the separate package
|
||||
`com.it_screen.edgevision.facereidpoc`. Start requires on-device confirmation
|
||||
that all adult test participants consent. Keep other people out of the camera view.
|
||||
The default build excludes the SFace weights and implementation.
|
||||
|
|
|
|||
4
build.sh
4
build.sh
|
|
@ -20,14 +20,14 @@ if [[ ! -f build/ort.aar ]]; then
|
|||
fi
|
||||
python3 tools/check-production-assets.py
|
||||
manifest=AndroidManifest.xml
|
||||
apk=build/EVAx10-Video-analitics-0.3.19.apk
|
||||
apk=build/EVAx10-Video-analitics-0.3.20.apk
|
||||
if [[ $variant == poc ]]; then
|
||||
python3 tools/check-poc-assets.py
|
||||
manifest=build/AndroidManifest-face-reid-poc.xml
|
||||
sed -e 's/package="com.it_screen.edgevision"/package="com.it_screen.edgevision.facereidpoc"/' \
|
||||
-e 's/android:name=".MainActivity"/android:name="com.it_screen.edgevision.MainActivity"/' \
|
||||
AndroidManifest.xml > "$manifest"
|
||||
apk=build/EVAx10-Video-analitics-0.3.19-Face-ReID-PoC.apk
|
||||
apk=build/EVAx10-Video-analitics-0.3.20-Face-ReID-PoC.apk
|
||||
fi
|
||||
rm -rf build/classes build/dex
|
||||
mkdir -p build/classes build/dex
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ final class FaceReId implements ReIdProvider<float[]> {
|
|||
}
|
||||
private ImageModel model;
|
||||
private float threshold;
|
||||
private String matchDetails = "";
|
||||
|
||||
@Override public String matchDetails() { return matchDetails; }
|
||||
|
||||
static ReIdProvider<float[]> create() { return new FaceReId(); }
|
||||
|
||||
|
|
@ -91,19 +94,30 @@ final class FaceReId implements ReIdProvider<float[]> {
|
|||
if (observation == null) return UNCERTAIN;
|
||||
long bestId = 0;
|
||||
float best = -2, runnerUp = -2;
|
||||
boolean missing = false;
|
||||
int comparable = 0;
|
||||
long runnerUpId = 0;
|
||||
for (VisitorSessions.Candidate candidate : candidates) {
|
||||
Enrollment enrollment = templates.get(candidate.id);
|
||||
if (enrollment == null) { missing = true; continue; }
|
||||
if (enrollment == null) continue;
|
||||
comparable++;
|
||||
float similarity = bestSimilarity(observation, enrollment);
|
||||
if (similarity > best) {
|
||||
runnerUp = best;
|
||||
runnerUpId = bestId;
|
||||
best = similarity;
|
||||
bestId = candidate.id;
|
||||
} else runnerUp = Math.max(runnerUp, similarity);
|
||||
} else if (similarity > runnerUp) {
|
||||
runnerUp = similarity;
|
||||
runnerUpId = candidate.id;
|
||||
}
|
||||
}
|
||||
if (best >= threshold && best - runnerUp >= AMBIGUITY_MARGIN) return bestId;
|
||||
return missing || best >= threshold - AMBIGUITY_MARGIN ? UNCERTAIN : 0;
|
||||
long result = best >= threshold && best - runnerUp >= AMBIGUITY_MARGIN ? bestId :
|
||||
comparable < candidates.size() || best >= threshold - AMBIGUITY_MARGIN ? UNCERTAIN : 0;
|
||||
matchDetails = String.format(java.util.Locale.ROOT,
|
||||
"comparable=%d best=V%d:%.3f runner_up=V%d:%.3f threshold=%.3f margin=%.3f result=%s",
|
||||
comparable, bestId, best, runnerUpId, runnerUp, threshold, AMBIGUITY_MARGIN,
|
||||
result > 0 ? "match" : result == 0 ? "below_distinct_cutoff" : "uncertain");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override public void observed(long visitorId, float[] observation) {
|
||||
|
|
|
|||
|
|
@ -691,8 +691,9 @@ public final class MainActivity extends Activity {
|
|||
}
|
||||
for (PersonTracker.Track track : tracker.tracks()) {
|
||||
if (track.state != PersonTracker.State.ACTIVE) continue;
|
||||
Face observedFace = assignments.get(track);
|
||||
float[] sample = visitorSessions.needsObservation(track.id) ?
|
||||
FaceReId.embed(reId, frame, assignments.get(track)) : null;
|
||||
FaceReId.embed(reId, frame, observedFace) : null;
|
||||
boolean awaitMoreEvidence = FaceReId.CONTROLLED_POC &&
|
||||
now - track.activeSince < 5000L;
|
||||
VisitorSessions.Assignment assignment;
|
||||
|
|
@ -701,6 +702,18 @@ public final class MainActivity extends Activity {
|
|||
} finally {
|
||||
if (sample != null) Arrays.fill(sample, 0);
|
||||
}
|
||||
if (FaceReId.CONTROLLED_POC && assignment.kind != VisitorSessions.Kind.CONTINUED &&
|
||||
(faceMs >= 0 || assignment.kind != VisitorSessions.Kind.DEFERRED)) {
|
||||
String faceDetails = observedFace == null ? "no_associated_face" :
|
||||
String.format(Locale.ROOT, "%.0fx%.0fpx confidence=%.3f eyes_px=%.1f",
|
||||
observedFace.box.width() * frame.getWidth(), observedFace.box.height() * frame.getHeight(),
|
||||
observedFace.confidence, observedFace.landmarks == null ? -1 :
|
||||
Math.hypot(observedFace.landmarks[2] - observedFace.landmarks[0],
|
||||
observedFace.landmarks[3] - observedFace.landmarks[1]));
|
||||
android.util.Log.i("EdgeVisionTrack", "decision track=" + track.id + " kind=" + assignment.kind
|
||||
+ " visitor=" + assignment.visitorId + " unique=" + visitorSessions.totalCreated()
|
||||
+ " face=" + faceDetails + " embedding=" + (sample != null) + " " + visitorSessions.observationDetails());
|
||||
}
|
||||
if (FaceReId.CONTROLLED_POC) visitorSessions.updateAge(track.id, track.analytics.averageAge());
|
||||
switch (assignment.kind) {
|
||||
case RECONNECTED:
|
||||
|
|
@ -868,6 +881,7 @@ public final class MainActivity extends Activity {
|
|||
}
|
||||
|
||||
private void addVisitEvent(String event) {
|
||||
if (FaceReId.CONTROLLED_POC) android.util.Log.i("EdgeVisionTrack", event);
|
||||
if (visitEvents.size() == 30) visitEvents.removeLast();
|
||||
visitEvents.addFirst("[" + eventClock.format(new Date()) + "] " + event);
|
||||
}
|
||||
|
|
@ -881,6 +895,7 @@ public final class MainActivity extends Activity {
|
|||
|
||||
private void reset() {
|
||||
inference.execute(() -> {
|
||||
if (FaceReId.CONTROLLED_POC) android.util.Log.i("EdgeVisionTrack", "RESET statistics");
|
||||
tracker.clear();
|
||||
visitorSessions.clear();
|
||||
visitEvents.clear();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ interface ReIdProvider<Observation> {
|
|||
long UNCERTAIN = -1;
|
||||
|
||||
boolean enabled();
|
||||
default String matchDetails() { return ""; }
|
||||
default boolean enrollmentComplete(long visitorId) { return false; }
|
||||
|
||||
/** Return a confidently matched candidate ID, zero for a distinct visitor, or UNCERTAIN when evidence is insufficient. */
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ final class VisitorSessions<Observation> {
|
|||
private final Map<Integer, Session> byTrack = new HashMap<>();
|
||||
private final Set<Integer> unresolved = new HashSet<>();
|
||||
private final int[] ageCounts = new int[AudienceAggregator.AGES.length];
|
||||
private String observationDetails = "";
|
||||
|
||||
String observationDetails() { return observationDetails; }
|
||||
|
||||
private long nextId = 1;
|
||||
private long totalCreated, repeated, uncertain;
|
||||
|
||||
|
|
@ -76,6 +80,7 @@ final class VisitorSessions<Observation> {
|
|||
}
|
||||
|
||||
Assignment observe(int trackId, long now, Observation observation, boolean awaitMoreEvidence) {
|
||||
observationDetails = "";
|
||||
Session session = byTrack.get(trackId);
|
||||
Kind kind = Kind.CONTINUED;
|
||||
if (session == null) {
|
||||
|
|
@ -86,10 +91,13 @@ final class VisitorSessions<Observation> {
|
|||
for (Session candidate : open.values()) {
|
||||
if (!candidate.visible) candidates.add(new Candidate(candidate.id, candidate.lastSeen));
|
||||
}
|
||||
observationDetails = "eligible=" + candidates.size() + " open=" + open.size()
|
||||
+ " waiting=" + awaitMoreEvidence;
|
||||
if (awaitMoreEvidence && observation == null) return new Assignment(0, Kind.DEFERRED);
|
||||
if (observation == null) match = ReIdProvider.UNCERTAIN;
|
||||
else if (!candidates.isEmpty()) {
|
||||
match = provider.match(observation, Collections.unmodifiableList(candidates));
|
||||
observationDetails += " " + provider.matchDetails();
|
||||
Session candidate = open.get(match);
|
||||
if (candidate != null && !candidate.visible) {
|
||||
session = candidate;
|
||||
|
|
|
|||
Loading…
Reference in New Issue