Jacob’s Tech Tavern

Jacob’s Tech Tavern

Apple Photos and Face Recognition in 512-D Hyperspace

Everyday ML to delight your users

Jacob Bartlett's avatar
Jacob Bartlett
Jul 07, 2026
∙ Paid

AI features are frequently whipped out and waved about in your face. You know what I’m talking about: empathetic but useless customer service droids. Auto-post-writing on social media. Email summaries (and filtering!) that nobody asked for.

Often, we’re not really the target audience; it’s so they can tell shareholders about their AI strategy (annoying but I guess better than what Meta is doing with the 20% layoffs…)

It’s not controversial to say the best kind of AI features are invisible, quietly improving products without you having to think about it. Recommender algorithms. Curation. Semantic search.

Apple Photos is a great case study. Say what you want about the dodgy iOS 26 redesign, but it’s fundamentally a solid product: it safeguards decades of your life in the cloud. It curates daily slideshows of memories. And it’s pretty darn good at working out who is who across your photos.

People & Pets lets you tap a face to see all the photos of that person.

Apple Photos “People & Pets” filters photos by face.

Facial recognition isn’t possible without some solid ML work: computing facial fingerprints across thousands of images and clustering like images into a library of family and friends, all in the background.

There’s no better way to understand a system than by jerry-rigging your own janky version, so that’s exactly what I did.


Contents

  • The Sample Project

  • Step #1: Finding Faces with Vision

  • Step #2: Computing Embeddings

  • Step #3: The Clustering Pipeline

  • Step #4: Optimising the Pipeline

  • Last Orders


The Sample Project

I couldn’t be arsed to decompile anything today, so can’t speak for Apple’s specific implementation, but the concepts of facial recognition software are a surprisingly straightforward 3-step pipeline:

  1. Detect faces in each photo via Vision.

  2. Turn each detected face into an embedding via ML models.

  3. Group similar embeddings into people via clustering algorithms.

The best part? This all works locally with on-device models, and works pretty damn well.

I’ll also share the sample project so you can go into much more detail. We will learn a whole lot about embeddings along the way. Quick spoiler for where we’re landing:

Projecting my 512-dimensional face embeddings into 3D geometry

Get the whole sample project on my GitHub repo now:

Get the sample project


Step #1: Finding Faces with Vision

The first step to building a library of faces is understanding which pixels of a given image are interesting to you.

Me and the boys at the pub, alongside some very subtle facial detection (redacting James’ face because he works for MI6)

Now while I think all pixels are beautiful, only a few bits of the image actually help us with facial recognition. That is, the faces. A photo has a vast quantity of information, but most of it is noise if you just want to match faces.

We need to find the coordinates of the image which actually contain faces.

Apple’s Vision framework has a built-in API for precisely this. Give VNDetectFaceRectanglesRequest an image, and it returns a list of bounding boxes around each face.

Detecting face rectangles with Vision · View gist

This doesn’t perform any work to identify anyone. It’s just rectangles.

Underwhelming, perhaps, but no less important. It’s our first building block.

Now we can ignore the rest of the photo and work face-by-face instead of image-by-image. It also helps to do a simple post-processing step and discard faces too small or low-confidence to be useful, like the blurry lad in the back of your concert selfie.

Filtering out tiny or low-confidence face detections · View gist

Step one is done. We have our list of rectangles associated with each image. Next, we convert the crops into… mathematics.


Step #2: Computing Embeddings

What is an embedding? A miserable little pile of secrets. It’s a fancy word for a vector, which is a fancy word for a list of numbers. A 512-item array of floats. If you like forensics-y metaphors, it’s a numerical fingerprint representing the image.

We create these embeddings by passing the pixels of a face image through the weights of our chosen face recognition model: pixels go in, embeddings go out.

Aside: how are facial recognition models trained?
As with most ML, you start with a huge labelled dataset, with many photos of each person across different poses, lighting, age, facial expression, and image quality, to ensure a model can learn that one person might be representable by a range of pixel values. From there, you train it the same way you train any neural network.

Now we know where to find faces, we are basically crunching geometry. Geometry like the spacing between your eyes, the position of your mouth, the shape of your skull. These properties tend to be constant between plastic surgeries.

If you’re a paid subscriber, now we get to the really fun bit:

  • Computing embedding vectors from our faces

  • Placing these on a 512-dimensional hypersphere,

  • Running clustering algorithms to group faces accurately

Paid members also get:

⚓️ Access my full library of 50 paywalled articles (including this one)
🚀 Read free articles a month before anyone else
🧵 Master concurrency with my full course and advanced training
🧑‍🚀 Get a free copy of my new eBook, “Land your iOS Tech Job”
❤️‍🩹 Support independent, sometimes funny, tech writing

Get 14 day free trial

User's avatar

Continue reading this post for free, courtesy of Jacob Bartlett.

Or purchase a paid subscription.
© 2026 Jacob Bartlett · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture