Machine Learning · USC Capstone
Real-Time Eye Contact Detection
A classifier that tells, frame by frame, whether a child is making eye contact with a robot, built for autism research at the USC Interaction Lab.
Overview
For my senior capstone in computer science at USC, I worked with a team of undergraduates in the USC Interaction Lab for a PhD candidate. Her research used the Nao, a small humanoid robot, to talk with young children and study how they behave.
One behaviour she wanted to measure was eye contact: in infants and small children, it can be an early indicator of autism. But the robot had no way to read a child's face and tell, in real time, whether they were looking at it.
Our job was to build that capability in a single semester. We scoped the problem, built our own training data, worked through a failed first model and delivered a classifier that runs on the robot's cameras as frames come in.
It was my first time taking a machine learning problem from end to end, and much of it carries straight into product work: define what success means before building, make sure the data matches the real user, treat a bad first result as information and ship where the user actually works.
Key product & technical decisions
Build on OpenFace instead of starting from pixels
With one semester, writing our own face tracker wasn't realistic. OpenFace, an open-source computer vision toolkit, already found facial landmarks, tracked gaze and estimated head pose. We spent our time on the part nobody had built yet: deciding, frame by frame, whether a child was making eye contact.
Treat “eye contact” as something to learn, not a fixed threshold
Our first idea was to use OpenFace's gaze angle alone and call anything near the camera “looking.” But eye contact with a camera is subjective and varies from person to person, so a single angle would be wrong for a lot of children. We redefined the problem as classification and let a model learn what looking at the camera actually looks like.
Train on the people the tool is for
OpenFace was trained on adults, and the researcher's subjects were infants and small children. Rather than hope an adult model carried over, we built our own training set: dozens of YouTube videos of infants talking to a camera, run through OpenFace's feature extraction for a frame-by-frame record of each face.
Make our own ground truth
No labeled data existed, so we created it. Using video annotation software, we marked every frame as looking or not looking and joined those labels to the OpenFace features. The result was about two hours of annotated video across dozens of children. It was slow, and it's the reason the model worked.
Fix overfitting by cutting features
The first test on new video went badly. OpenFace produces more than 100 features describing a face, and the model was memorising noise. We went back to the documentation and retrained on smaller subsets, landing on 10 to 15 features: gaze direction, the x-y-z position of the head and its rotation. Accuracy improved sharply.
Compare models before picking one
With the features settled, we tested several classifiers in scikit-learn against the same data. K-Nearest Neighbors came out ahead and reached 98% accuracy classifying video it hadn't seen during training.
Ship it where it would run: inside the robot's pipeline
A notebook result wasn't useful to the researcher; she needed real-time readings on the robot. We serialised the model with Joblib and edited OpenFace so each frame is classified as soon as its features are extracted, which meant the modified OpenFace only had to be installed on the Nao robot to work with its eye cameras. With no infants available for live testing, we tried it on ourselves over webcams and found it worked very well on adults too.
By the numbers
~2 hrs
Of infant video annotated frame by frame
10–15
Features kept out of OpenFace's 100+ after fixing overfitting
98%
Accuracy classifying unseen video
1
Semester from problem to real-time model