58 lines
2.9 KiB
Java
58 lines
2.9 KiB
Java
package com.it_screen.edgevision;
|
|
|
|
import java.util.List;
|
|
|
|
public final class FaceReIdTest {
|
|
public static void main(String[] args) {
|
|
ReIdProvider<float[]> provider = FaceReId.create();
|
|
FaceReId.setThreshold(provider, .55f);
|
|
VisitorSessions<float[]> sessions = new VisitorSessions<>(provider);
|
|
|
|
long first = sessions.observe(1, 0, vector(1, 0)).visitorId;
|
|
sessions.observe(1, 1000, vector(.8f, .6f));
|
|
sessions.trackClosed(1);
|
|
check(sessions.observe(2, 120000, vector(0, -1), true).kind == VisitorSessions.Kind.DEFERRED &&
|
|
sessions.totalCreated() == 1, "first low-quality comparison does not create a duplicate");
|
|
VisitorSessions.Assignment returned = sessions.observe(2, 121000, vector(.28f, .96f), true);
|
|
check(returned.kind == VisitorSessions.Kind.RECONNECTED && returned.visitorId == first,
|
|
"return with a different track and moderately changed vector");
|
|
check(sessions.totalCreated() == 1 && sessions.repeatedCount() == 1, "deduplicated counters");
|
|
sessions.trackClosed(2);
|
|
|
|
VisitorSessions.Assignment unknown = sessions.observe(3, 122000, null);
|
|
check(unknown.kind == VisitorSessions.Kind.UNCERTAIN && sessions.uncertainCount() == 1 &&
|
|
sessions.totalCreated() == 1,
|
|
"missing observation leaves comparison uncertain");
|
|
check(sessions.observe(3, 122500, null).kind == VisitorSessions.Kind.DEFERRED &&
|
|
sessions.uncertainCount() == 1, "uncertainty is reported once per track");
|
|
check(sessions.observe(3, 123000, vector(1, 0)).kind == VisitorSessions.Kind.RECONNECTED &&
|
|
sessions.totalCreated() == 1, "an unresolved track can bind later without creating a duplicate");
|
|
sessions.trackClosed(3);
|
|
|
|
List<VisitorSessions.Candidate> pair = List.of(new VisitorSessions.Candidate(first, 0),
|
|
new VisitorSessions.Candidate(20, 0));
|
|
provider.observed(20, vector(1, 0));
|
|
check(provider.match(vector(1, 0), pair) == ReIdProvider.UNCERTAIN, "tied candidates stay uncertain");
|
|
provider.expired(20);
|
|
check(provider.match(vector(0, -1), pair.subList(0, 1)) == 0, "distinct embedding");
|
|
sessions.expire(183000, 60000);
|
|
check(sessions.openCount() == 0 && provider.match(vector(1, 0), pair.subList(0, 1)) == ReIdProvider.UNCERTAIN, "timeout removes the embedding");
|
|
|
|
sessions.observe(4, 183000, vector(1, 0));
|
|
sessions.closeSessions();
|
|
check(sessions.openCount() == 0 && sessions.totalCreated() == 2, "stop closes sessions, retaining count");
|
|
System.out.println("Face Re-ID tests passed");
|
|
}
|
|
|
|
private static float[] vector(float a, float b) {
|
|
float[] v = new float[128];
|
|
v[0] = a;
|
|
v[1] = b;
|
|
return v;
|
|
}
|
|
|
|
private static void check(boolean condition, String message) {
|
|
if (!condition) throw new AssertionError(message);
|
|
}
|
|
}
|