A face recognition system stores a gallery of embeddings with known identities. At test time a probe may belong to a known person or to someone the system has never seen. Following Murphy's book, match the probe to its nearest gallery item and, if there is no good enough match, declare it novel.
Implement:
open_set_predict(gallery_emb, gallery_ids, probe_emb, tau): L2-normalise every gallery and probe row, find for each probe the gallery row with the largest cosine similarity (ties go to the smaller gallery index), and predict that row's identity if the similarity is at least tau, otherwise -1. Return an integer numpy array, one prediction per probe.open_set_metrics(pred, true_ids, gallery_ids): a probe is known when its true identity appears in gallery_ids, otherwise unknown. Return (dir, far) as floats:
dir (detection and identification rate): the fraction of known probes predicted with exactly their true identity;far (false accept rate): the fraction of unknown probes that were not rejected (prediction other than -1).
If there are no known (or no unknown) probes, the corresponding rate is 0.0.best_threshold(gallery_emb, gallery_ids, probe_emb, true_ids, taus): evaluate every threshold in taus and return (tau, score) maximising the balanced score , taking the first such tau in list order on ties.