Hair-hunting computer benefits from deep learning

Toronto researchers are teaching computers to recognize hair. They hope the technique might one day be applied to more important applications, like the visual detection of skin cancer, or even the development of safer self-driving cars.

Similar algorithms might one day be used to help identify skin cancer or improve self-driving cars

Humans are good at telling the difference between what's hair and not hair. Computers, not so much. Runner-up contestant Yanely Salgado, 31, displays her hairdo during an Afro hair contest in Havana in June 2015. (Desmond Boylan/Associated Press)

A pair of University of Toronto researchers have been giving their computer a crash course in human hair. 

Computers are pretty good at recognizing faces, but less so at what surrounds them. That's where Parham​ Aarabi and Wenzhangzhi Guo come in.

With the help of machine learning — and a little human input — the two researchers have been teaching computer vision algorithms to more accurately identify hair.

Eventually, Aarabi hopes the technique can be applied to more important applications, like the visual detection of skin cancer, or even the development of safer self-driving cars.

"If you could take [dermatologists'] expertise, and then train a deep neural net to then realize some features or details that even doctors won't be aware of, that would be just amazing," Aarabi said.

But hair — something that most people have — is a good place to start.

Deep learning

Their research relies on neural networks, or computer code that mimics how layers of neurons in the brain process information. With enough information, neural networks are remarkably adept at finding patterns in seas of information.

When fed millions of videos, photos or audio recordings, they have learned to identify photos with cats, or perform more accurate language translation — a technique known as deep learning.

On the left, an aggressive hair-masking algorithm. In the middle, a conservative hair-masking algorithm. On the right, a hair-masking algorithm that uses deep learning. The red overlay represents areas of the image each algorithm has determined to be hair. (IEEE Transactions on Neural Networks & Learning Systems)

In this case, however, researchers only had 100 photos with corresponding cutouts of human hair for each. That wasn't nearly enough data to teach their neural network to identify hair on its own, they found. So they enlisted human expertise to help their neural network out.

Humans, of course, are particularly good at being able to tell what's hair, and what's not. We rely on a number of characteristics, such as colour, texture and the direction in which strands of hair flow. Aarabi and Guo took those characteristics, turned them into rules, and trained their neural network to look for only the parts of images that humans would mostly likely classify as hair. 

The result, according to their paper, was a nine per cent improvement in performance over their previous hair-detection method, which did not rely on deep learning. In fact, the algorithm worked so well, according to Arabi, that it was able to identify patches of hair that the human rules used to train the neural network didn't catch.

Future potential

The research is an extension of work that Aarabi and Guo have been doing at their company ModiFace, which develops augmented reality software for the beauty industry. Smartphone apps powered by ModiFace technology can show users how a particular brand of makeup might look on their face, or how a new hair colour might look — the latter of which relies on the ModiFace software's ability to accurately segment, or separate out hair.

But Aarabi believes that combining human experience and machine learning has the potential to help in other fields. Dermatologists, for example, have visual cues that help them identify potentially cancerous moles, while drivers rely on rules to stay safe while on the road — both of which could be used to more effectively train a machine learning algorithm in the absence of a larger data set.

"Hair segmentation may not be the world's most important problem, but it was one that we could really quantify very accurately," he said. "And sometimes having toy examples are very useful for understanding how the algorithm is working. For that purpose, it actually served it quite well."

Their research will appear in an upcoming issue of the journal IEEE Transactions on Neural Networks & Learning Systems, but has already been published online.


Matthew Braga

Senior Technology Reporter

Matthew Braga is the senior technology reporter for CBC News, where he covers stories about how data is collected, used, and shared. You can contact him via email at For particularly sensitive messages or documents, consider using Secure Drop, an anonymous, confidential system for sharing encrypted information with CBC News.