Commit 874a2926e2c39db2c0dbe746a8497fbbb4df7571
1 parent
f518fc3b
partial draft of L2 normalization in Likely
Showing
1 changed file
with
40 additions
and
3 deletions
share/openbr/likely/face_recognition.tex
| @@ -50,6 +50,8 @@ face-recognition := | @@ -50,6 +50,8 @@ face-recognition := | ||
| 50 | \end{likely} | 50 | \end{likely} |
| 51 | 51 | ||
| 52 | Throughout the remainder of this document we will append additional steps to this function, building up the entire algorithm one transformation at a time. | 52 | Throughout the remainder of this document we will append additional steps to this function, building up the entire algorithm one transformation at a time. |
| 53 | +It is the responsibility of each section in this document to update the \emph{face-recognition} function and the training data. | ||
| 54 | +In this way the sections maintain independence, and the algorithm can be changed by inserting, removing, or editing sections of this document. | ||
| 53 | 55 | ||
| 54 | Note that the remainder of this document assumes that the global variable \emph{data} is defined, and contains the appropriate training samples. | 56 | Note that the remainder of this document assumes that the global variable \emph{data} is defined, and contains the appropriate training samples. |
| 55 | 57 | ||
| @@ -60,8 +62,43 @@ data.frames | @@ -60,8 +62,43 @@ data.frames | ||
| 60 | 62 | ||
| 61 | \section{...} | 63 | \section{...} |
| 62 | This section serves as a placeholder for the unwritten algorithm steps. | 64 | This section serves as a placeholder for the unwritten algorithm steps. |
| 63 | -There are a lot of sections that haven't been written yet, including face detection, registration and representation! | ||
| 64 | -In fact, only the final section of the algorithm has been written. | 65 | +There are a lot of steps that haven't been written yet, including face detection, registration and representation! |
| 66 | +In fact, only the final few sections of the algorithm have been written. | ||
| 67 | + | ||
| 68 | +\section{L2 Normalization} | ||
| 69 | +We wish to normalize every feature vector to a unit L2 norm, ensuring that they live on a high-dimensional unit sphere. | ||
| 70 | +Such a normalization has been observed to improve accuracy when comparing feature vectors using a Euclidean distance. | ||
| 71 | + | ||
| 72 | +\begin{likely} | ||
| 73 | +normalize-l2 := | ||
| 74 | + src :-> | ||
| 75 | + { | ||
| 76 | + squared-sum := 0.f32.$ | ||
| 77 | + add-element := | ||
| 78 | + (mat t y x c) :-> | ||
| 79 | + squared-sum :<- (+ squared-sum (mat c x y t).(cast squared-sum).sq) | ||
| 80 | + src:iter-elements add-element | ||
| 81 | + alpha := (/ 1 (sqrt squared-sum)) | ||
| 82 | + | ||
| 83 | + dst := src.imitate | ||
| 84 | + (dst src alpha) :=> | ||
| 85 | + dst :<- src | ||
| 86 | + } | ||
| 87 | +\end{likely} | ||
| 88 | + | ||
| 89 | +Now we can re-define \texttt{face-recognition} to append L2 normalization. | ||
| 90 | + | ||
| 91 | +\begin{likely} | ||
| 92 | +face-recognition := | ||
| 93 | + src :-> | ||
| 94 | + src.face-recognition.normalize-l2 | ||
| 95 | +\end{likely} | ||
| 96 | + | ||
| 97 | +And project the training data. | ||
| 98 | + | ||
| 99 | +\begin{likely} | ||
| 100 | +data := [ data.normalize-l2 ] | ||
| 101 | +\end{likely} | ||
| 65 | 102 | ||
| 66 | \section{Quantization} | 103 | \section{Quantization} |
| 67 | The goal of quantization is to rescale and cast feature vector dimensions into 8-bit unsigned integers. | 104 | The goal of quantization is to rescale and cast feature vector dimensions into 8-bit unsigned integers. |
| @@ -98,7 +135,7 @@ face-recognition := | @@ -98,7 +135,7 @@ face-recognition := | ||
| 98 | And project the training data. | 135 | And project the training data. |
| 99 | 136 | ||
| 100 | \begin{likely} | 137 | \begin{likely} |
| 101 | -data := data.quantize | 138 | +data := [ data.quantize ] |
| 102 | \end{likely} | 139 | \end{likely} |
| 103 | 140 | ||
| 104 | And report some statistics. | 141 | And report some statistics. |