--- title: Face Clustering keywords: fastai sidebar: home_sidebar nb_path: "nbs/indexers.FaceClusteringIndexer.indexer.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

class FaceClusteringIndexer[source]

FaceClusteringIndexer(*args, **kwargs) :: IndexerBase

Clusters faces on photos.

{% endraw %} {% raw %}
{% endraw %} {% raw %}
test_registration(FaceClusteringIndexer)
{% endraw %}

Toy dataset

You can test the model on your favorite images, we use 2 images from the modern family tv show as input and run the indexer. As per usual, you can run the indexer by calling indexer.index().

{% raw %}
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")]
data   = IndexerData(photos=photos)
cluster_indexer = FaceClusteringIndexer()
items = cluster_indexer.index(data)
[32, 16, 8] {'32': {'SCALES': (32, 16), 'BASE_SIZE': 16, 'RATIOS': (1.0,), 'ALLOWED_BORDER': 9999}, '16': {'SCALES': (8, 4), 'BASE_SIZE': 16, 'RATIOS': (1.0,), 'ALLOWED_BORDER': 9999}, '8': {'SCALES': (2, 1), 'BASE_SIZE': 16, 'RATIOS': (1.0,), 'ALLOWED_BORDER': 9999}}
use_landmarks True
Indexing 2 photos
100.00% [2/2 00:01<00:00]
100.00% [22/22 00:03<00:00]
{% endraw %}

Inspecting the output

This generates a few data items for you, from various types. It creates photos and their files, which correspond to the crops of the faces and it creates Person items for the people in the crops.

{% raw %}
set([type(i) for i in items])
{integrators.data.schema.File,
 integrators.data.schema.Person,
 integrators.indexers.facerecognition.photo.IPhoto}
{% endraw %}

The Person and Photo items are connected with an edge, called "occurence", you can inspect them as follows:

{% raw %}
people = [x for x in items if isinstance(x, Person) and len(x.occurence) >=1]
print(len(people))
7
{% endraw %}

Simluate run from pod

You can also test the full pipelines as if you are running it from the pod. You can do that as follows.

{% raw %}
client = PodClient()
{% endraw %} {% raw %}
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")]
indexer = Indexer.from_data(indexerClass="FaceClusteringIndexer", name="FaceClustering")
indexer_run = IndexerRun.from_data(progress=0, targetDataType="Photo")

for x in [indexer, indexer_run] + photos : client.create(x)
assert client.create_edge(Edge(indexer_run, indexer, "indexer"))
{% endraw %} {% raw %}
run_integrator(pod_full_address=DEFAULT_POD_ADDRESS,
               integrator_run_uid=indexer_run.uid,
               database_key=client.database_key,
               owner_key=client.owner_key)
{% endraw %} {% raw %}
client.delete_all()
[32, 16, 8] {'32': {'SCALES': (32, 16), 'BASE_SIZE': 16, 'RATIOS': (1.0,), 'ALLOWED_BORDER': 9999}, '16': {'SCALES': (8, 4), 'BASE_SIZE': 16, 'RATIOS': (1.0,), 'ALLOWED_BORDER': 9999}, '8': {'SCALES': (2, 1), 'BASE_SIZE': 16, 'RATIOS': (1.0,), 'ALLOWED_BORDER': 9999}}
use_landmarks True
{% endraw %}