Face Detector

Google Inc
Human
Face
Emotion
Supported Device
Vision Kit

The Face Detector model locates and identifies faces from an image. It also provides a “joy score” for each face.

Already included in the AIY Vision Kit SD card image

Download

Demo: Face Detector

This demo uses your Vision Kit camera or an image to guess how many faces are present.

What you’ll need

Assembled Vision Kit with the latest SD card image.

Step 1: Get connected

First, make sure you’re connected to your kit and have a terminal open. All the following commands must be performed on your kit's Raspberry Pi.

Step 2: Stop your current demo

Your Vision Kit might be running another demo, such as the Joy Detector, which runs by default when your kit is turned on. You can tell it's running if the green privacy LED on the front of the kit is illuminated. You can stop the Joy Detector with the following command:

sudo systemctl stop joy_detection_demo

Or if you're running another demo that uses the camera, press Control+C in the terminal to stop it.

Step 3: Run Face Detector with a saved image

First, find an image that includes one or more faces and download it with the command wget <URL>.

For example, here's an image licensed under Creative Commons:

wget https://farm3.staticflickr.com/4109/5031905069_cd67b182e3_o.jpg \
  -O faces.jpg

The file is downloaded to the current directory, named faces.jpg.

Then run the demo with the following command:

~/AIY-projects-python/src/examples/vision/face_detection.py \
  --input faces.jpeg --output faces-result.jpeg

For each face detected, the demo prints information such as the face score and joy score. It also creates an image to the output location, which is a copy of the image that includes a box around each face.

If no face was detected, nothing prints to the screen. Try using an image in which the faces are more well lit and directly facing the camera.

Step 4: Run Face Detector with the Vision Kit camera

You can also detect faces in realtime using the Vision Kit's camera.

Just run the following command, specifying the number of consecutive inferences you want to perform (try 20 to start):

~/AIY-projects-python/src/examples/vision/face_detection_camera.py \
  --num_frames 20

Note: If you do not specify num_frames, the demo will continue forever, until you stop it by pressing Control+C.

It takes some time for the demo to start. Please be patient. Once it starts, detection of faces in each frame is very fast.

Now point that camera at some faces! You’ll notice in your terminal window that the kit prints the number of faces in each frame. And if you've connected your kit to a monitor, you'll see a window showing what the camera sees, with boxes around each detected face.

If every line printed in the terminal says num_faces=0, then the model didn’t detect any faces. Try again but be sure your subject is well lit from the front and there are no bright lights directly behind them.

If you ran into an error, check Help.