I'm developing a face recognizing application using the face_recognition Python library.
The faces are encoded as 128-dimension floating-point vectors. In addition to this, each named known person has a variance value, which is refined iteratively for each new shot of the face along with the mean vector. I took the refining formula from Wikipedia.
I'm getting some false positives with the recognized faces, which I presume is because the library was developed primarily for Western faces whereas my intended audience are primarily Southern-Eastern Asian. So my primary concern with my code, is about whether or not I had gotten the mathematics correct.
Here's my refining algorithm in Python
import sys from functools import reduce from math import hypot # fake testing data. # new reference face. refenc = (0.2, 0.25, 0.4, 0.5) * 32 # previous face encoding and auxiliary info. baseenc = (0.2, 0.3, 0.4, 0.5) * 32 v = 0.01 # variance n = 3 # current iteration n = min(n, 28) # heuristically limited to 28. vnorm = lambda v: reduce(hypot, v) vdiff = lambda u, v: list(map(lambda s,t:s-t, u, v)) delta1 = vdiff(refenc, baseenc) if( vnorm(delta1) > 0.4375 and n > 1 ): sys.exit() # possibly selected wrong face. pass newenc = [ baseenc[i] + delta1[i] / n for i in range(128) ] delta2 = vdiff(delta1, newenc) v = v*(n-1)/n + vnorm(delta1)*vnorm(delta2)/n print(repr((newenc, v, n)))
: I used struct.(un)pack to serialize in binary to save space, because the
repr of the data is too big.