--- title: FaceClustering Model keywords: fastai sidebar: home_sidebar nb_path: "nbs/indexers.FaceClusteringIndexer.Models.ipynb" ---
This module contains functionality to cluster faces on images by person. It uses the FaceEmbeddingModel
to extract faces from photos, crop them and create embeddings for each face. These are embeddings are used as input for this module to cluster them based on network topology generated by the the graph of all embeddings.
You can test the model on your favorite images, we use 2 images from the modern family tv show as input.
data_dir = PYI_TESTDATA / "photos" / "faceclustering"
photos = [IPhoto.from_path(path=x, size=640) for x in data_dir.ls() if str(x).endswith("jpg")]
show_images(photos)
You can initialize the model and run it on your data with a few very simple function calls
model = FaceClusteringModel()
crops, crop_cluster_labels = model.run(photos)
You can group the photos from a cluster using the group_clusters
functions, and easily visualize the results.
for i, photos in enumerate(group_clusters(crops, crop_cluster_labels)[:3]):
print(f"Cluster {i}")
show_images(photos)