Bird
Raised Fist0
Computer Visionml~20 mins

Face embedding and comparison in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Face Embedding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does a face embedding represent?

Imagine you have a photo of a face. A face embedding is a way to turn that photo into a list of numbers. What do these numbers represent?

AThe coordinates of the face in the original image.
BThe exact pixel colors of the face image stored as numbers.
CA random set of numbers unrelated to the face's appearance.
DA unique numeric summary capturing important features of the face for comparison.
Attempts:
2 left
💡 Hint

Think about how a fingerprint summarizes unique patterns.

❓ Predict Output
intermediate
2:00remaining
Output of cosine similarity between two face embeddings

Given two face embeddings as numpy arrays, what is the output of the cosine similarity calculation?

Computer Vision
import numpy as np
embedding1 = np.array([1, 0, 0])
embedding2 = np.array([0, 1, 0])
cos_sim = np.dot(embedding1, embedding2) / (np.linalg.norm(embedding1) * np.linalg.norm(embedding2))
print(round(cos_sim, 2))
A0.00
B1.00
C0.50
D-1.00
Attempts:
2 left
💡 Hint

Cosine similarity measures angle between vectors; orthogonal vectors have similarity zero.

❓ Model Choice
advanced
2:00remaining
Best model type for generating face embeddings

Which type of neural network model is best suited to generate face embeddings that capture facial features effectively?

ARecurrent Neural Network (RNN) trained on text data
BDecision tree trained on tabular data
CConvolutional Neural Network (CNN) trained on face images
DFully connected network trained on random noise
Attempts:
2 left
💡 Hint

Think about models good at processing images.

❓ Metrics
advanced
2:00remaining
Choosing a metric for face embedding comparison

You have two face embeddings and want to decide if they belong to the same person. Which metric is most commonly used for this comparison?

AMean squared error
BCosine similarity
CAccuracy score
DCross-entropy loss
Attempts:
2 left
💡 Hint

Think about measuring angle similarity between vectors.

🔧 Debug
expert
2:00remaining
Why does this face embedding comparison code fail?

Consider this code snippet to compare two face embeddings:

embedding1 = [0.1, 0.2, 0.3]
embedding2 = [0.1, 0.2, 0.3]
cos_sim = sum(embedding1 * embedding2) / (sum(embedding1**2)**0.5 * sum(embedding2**2)**0.5)
print(round(cos_sim, 2))

What error will this code raise?

ATypeError: can't multiply sequence by sequence
BZeroDivisionError: division by zero
CNameError: name 'embedding1' is not defined
DNo error, outputs 1.00
Attempts:
2 left
💡 Hint

Look at how lists are multiplied in Python.

Practice

(1/5)
1. What is the main purpose of face embedding in face recognition systems?
easy
A. To detect faces in an image
B. To change the face image colors
C. To crop the face from the image
D. To convert a face image into a unique list of numbers

Solution

  1. Step 1: Understand face embedding

    Face embedding transforms a face image into a unique numeric vector representing its features.
  2. Step 2: Identify the purpose

    This numeric vector helps compare faces by their features, not by raw pixels.
  3. Final Answer:

    To convert a face image into a unique list of numbers -> Option D
  4. Quick Check:

    Face embedding = unique number list [OK]
Hint: Face embedding means turning face into numbers [OK]
Common Mistakes:
  • Confusing embedding with face detection
  • Thinking embedding changes image colors
  • Assuming embedding crops the face
2. Which Python code snippet correctly computes the Euclidean distance between two face embeddings emb1 and emb2 stored as lists?
easy
A. distance = sum((a - b)**2 for a, b in zip(emb1, emb2)) ** 0.5
B. distance = abs(emb1 - emb2)
C. distance = emb1 + emb2
D. distance = max(emb1, emb2)

Solution

  1. Step 1: Recall Euclidean distance formula

    Euclidean distance is the square root of sum of squared differences between corresponding elements.
  2. Step 2: Match code to formula

    distance = sum((a - b)**2 for a, b in zip(emb1, emb2)) ** 0.5 uses a generator to compute squared differences, sums them, then takes square root, matching the formula.
  3. Final Answer:

    distance = sum((a - b)**2 for a, b in zip(emb1, emb2)) ** 0.5 -> Option A
  4. Quick Check:

    Euclidean distance = sqrt(sum of squared differences) [OK]
Hint: Euclidean distance = sqrt of sum of squared differences [OK]
Common Mistakes:
  • Using abs() on lists causes error
  • Adding lists concatenates, not distance
  • Using max() does not measure distance
3. Given the following code, what is the printed output?
import numpy as np
emb1 = np.array([0.1, 0.2, 0.3])
emb2 = np.array([0.1, 0.25, 0.35])
distance = np.linalg.norm(emb1 - emb2)
print(round(distance, 3))
medium
A. 0.050
B. 0.100
C. 0.071
D. 0.150

Solution

  1. Step 1: Calculate difference vector

    emb1 - emb2 = [0.1-0.1, 0.2-0.25, 0.3-0.35] = [0, -0.05, -0.05]
  2. Step 2: Compute Euclidean norm

    Distance = sqrt(0^2 + (-0.05)^2 + (-0.05)^2) = sqrt(0 + 0.0025 + 0.0025) = sqrt(0.005) ≈ 0.0707
  3. Final Answer:

    0.071 -> Option C
  4. Quick Check:

    Distance ≈ 0.071 [OK]
Hint: Subtract vectors, then sqrt of sum squares for distance [OK]
Common Mistakes:
  • Forgetting to square differences
  • Rounding incorrectly
  • Mixing up emb1 and emb2 order
4. The following code tries to compare two face embeddings but raises an error. What is the error and how to fix it?
emb1 = [0.1, 0.2, 0.3]
emb2 = [0.1, 0.25, 0.35]
distance = (emb1 - emb2).norm()
print(distance)
medium
A. Lists do not support subtraction; convert to numpy arrays first
B. norm() is not a valid method; use length() instead
C. emb1 and emb2 must be strings, not lists
D. Missing import statement for math module

Solution

  1. Step 1: Identify the error cause

    Subtracting two Python lists causes a TypeError because lists do not support '-' operator.
  2. Step 2: Fix by converting lists to numpy arrays

    Convert emb1 and emb2 to numpy arrays to enable element-wise subtraction and use numpy.linalg.norm() for distance.
  3. Final Answer:

    Lists do not support subtraction; convert to numpy arrays first -> Option A
  4. Quick Check:

    List subtraction error fixed by numpy arrays [OK]
Hint: Use numpy arrays for math on lists [OK]
Common Mistakes:
  • Trying to use norm() on lists
  • Ignoring TypeError from list subtraction
  • Assuming norm() is built-in for lists
5. You have two face embeddings: embA = [0.3, 0.4, 0.5] and embB = [0.31, 0.39, 0.52]. You want to decide if they belong to the same person using a threshold of 0.05 on Euclidean distance. Which code correctly implements this decision?
hard
A. distance = max(abs(a - b) for a, b in zip(embA, embB)) if distance > 0.05: print('Same person') else: print('Different person')
B. distance = sum((a - b)**2 for a, b in zip(embA, embB)) ** 0.5 if distance < 0.05: print('Same person') else: print('Different person')
C. distance = sum(abs(a - b) for a, b in zip(embA, embB)) if distance < 0.05: print('Different person') else: print('Same person')
D. distance = sum((a + b)**2 for a, b in zip(embA, embB)) ** 0.5 if distance < 0.05: print('Same person') else: print('Different person')

Solution

  1. Step 1: Calculate Euclidean distance correctly

    distance = sum((a - b)**2 for a, b in zip(embA, embB)) ** 0.5 if distance < 0.05: print('Same person') else: print('Different person') computes Euclidean distance as sqrt of sum of squared differences, which is the right metric.
  2. Step 2: Apply threshold logic

    If distance is less than 0.05, print 'Same person'; else 'Different person'. This matches the problem statement.
  3. Final Answer:

    distance = sum((a - b)**2 for a, b in zip(embA, embB)) ** 0.5 if distance < 0.05: print('Same person') else: print('Different person') -> Option B
  4. Quick Check:

    Euclidean distance < threshold means same person [OK]
Hint: Use Euclidean distance and compare with threshold [OK]
Common Mistakes:
  • Using max difference instead of Euclidean distance
  • Reversing the if condition logic
  • Adding embeddings instead of subtracting
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard