--- title: FaceRecognitionIndexer keywords: fastai sidebar: home_sidebar nb_path: "nbs/indexers.FaceRecognitionIndexer.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

class FaceRecognitionIndexer[source]

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

Recognizes photos from faces.

{% endraw %} {% raw %}
{% endraw %} {% raw %}

class IPhoto[source]

IPhoto(file=None, *args, **kwargs) :: Photo

Provides a base class for all items. All items in the schema inherit from this class, and it provides some basic functionality for consistency and to enable easier usage.

{% endraw %} {% raw %}
{% endraw %} {% raw %}

show_images[source]

show_images(images, cols=3, titles=None)

{% endraw %}

Example

{% raw %}
indexer = FaceRecognitionIndexer()
{% endraw %} {% raw %}
photo = IPhoto.from_data(file=PYI_TESTDATA / "photos" / "facerecognition" / "celebs.jpg")
boxes, landmarks = indexer.predict_boundingboxes(photo)
{% endraw %} {% raw %}
photo.draw_boxes(boxes)
Plotting 12 face boundingboxes
{% endraw %} {% raw %}
crops = photo.get_crops(boxes, landmarks)
{% endraw %}

Lets get two random faces from our photo

{% raw %}
show_images([crops[0], crops[1]])
{% endraw %}

And check if they are the same

{% raw %}
try:
    similarity =  indexer.compare(crops[0], crops[1])
    assert similarity < 0.5
finally:
    print("Not the same person")
Not the same person
{% endraw %}

Compute similarity for photo's of the same person

{% raw %}
ellen1 = IPhoto.from_data(file=PYI_TESTDATA / "photos" / "facerecognition" / "ellen1.png")
ellen2 = IPhoto.from_data(file=PYI_TESTDATA / "photos" / "facerecognition" / "ellen2.png")
{% endraw %} {% raw %}
show_images([ellen1.data, ellen2.data])
{% endraw %} {% raw %}
try:
    sim = indexer.compare(ellen1.data, ellen2.data)
    assert sim > 0.5
finally:
    print("Same person")
Same person
{% endraw %}

Plotting crops

When we plot the crops, we see that our model actually is doing some magic behind the scenes to normalize and scale our images.

{% raw %}
photo.plot_crops(boxes, landmarks)
# show_images(crops, cols=4)
{% endraw %}