v9.1.1
Menu

Euclidean Distance for Face Embeddings

easyFREEFace RecognitionEmbeddingsCV: Recognition

You are given two face embeddings (vectors) and need to calculate the Euclidean distance between them.

Face recognition systems convert face images to fixed-length vectors (embeddings). Similar faces produce similar embeddings, so the distance between embeddings indicates how similar two faces are.

The Euclidean distance (L2 distance) is:

d(a,b)=∑i=1n(ai−bi)2=∥a−b∥2d(a, b) = \sqrt{\sum_{i=1}^{n} (a_i - b_i)^2} = \|a - b\|_2

Lower distance = more similar faces.

Typical thresholds: distance < 0.6 might indicate same person, distance > 1.0 likely different people.

Example

Input
a = [1, 0, 0]
b = [0, 1, 0]
Output
1.4142
Reasoning
  • a and b are two face embeddings of the same length (here 3). Each number is one coordinate of a point in embedding space, so the two lists are compared position by position.
  • Difference per coordinate: a−b=(1−0, 0−1, 0−0)=(1,−1,0)a - b = (1-0,\ 0-1,\ 0-0) = (1, -1, 0).
  • Square each difference: 12=11^2 = 1, (−1)2=1(-1)^2 = 1, 02=00^2 = 0. Squaring removes the sign, so overshooting or undershooting a coordinate counts the same.
  • Add the squares, 1+1+0=21 + 1 + 0 = 2, then take the square root: 2≈1.414213…\sqrt{2} \approx 1.414213\ldots, which rounded to 4 decimal places is 1.4142.
  • The result is a single non-negative float, not a vector. Notice the inputs are perpendicular unit vectors, so the distance is the diagonal of a unit square; by the description's thresholds (above 1.0) these would be judged different people.
  • Two identical embeddings would give a distance of exactly 00: the same point in space.

Constraints

  • a and b are lists of floats (embeddings) of the same length
  • Return distance rounded to 4 decimal places

Learn this in

More from CV: Recognition

solution.py

Test results

Sign in to run your code against the test cases.