{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Celebs vs. Mortals: Facial Recognition in Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After watching way too much Game of Thrones and Ink Master, I started wondering what it is that makes a celebrity standout from the rest of us. Are there features, especially facial features, that can distinguish celebrities from common folk? \n", "\n", "
\n", "\n", "\n", "I put this question out of my mind until recently, while looking for interesting applications of datamining Twitter, I stumbled on [AlchemyAPI, an IBM Company](http://www.alchemyapi.com/api/face-detection/urls.html). `AlchemyAPI` provides a high-level interface to deep-learning tools. They offer a suite of natural language processing tools, for example the ability to have a computer *read* a newsarticle, extract the relevant people and ideas, and decide if they are of favorable sentiment. [Try out the webdemo, it's really cool.](http://www.alchemyapi.com/products/demo/alchemylanguage) They also offer computer vision tools, of particular interest to me, an API for facial recognition and extraction. They provide [9 SDK's](http://www.alchemyapi.com/developers/sdks), including one for `Python`. Python also happens to be a great language for data and image analysis with libraries like [scikit-image](http://scikit-image.org/), [IPython](http://ipython.org/), and [matplotlib](http://matplotlib.org/), and there's a lot of cool stuff to be done with faces.\n", "\n", "\"HTML5\n", "\n", "
\n", "\n", "This demo will compare age and gender predictions of faces, automatically extracted from web images, between me, my friends, and some of our favorite celebrities. In regard to facial recognition and analysis, `AlchemyAPI` does all of the hard work. I can then simply use some `scikit-image` and `matplotlib` Py-Fu to visualize the images, and rank them by age and gender scores.\n", "\n", "
\n", "\n", "**If you want to try this for yourself, you'll need the following:**\n", "\n", " 1. [AlchemyAPI Python SDK](https://github.com/AlchemyAPI/alchemyapi_python) (Must use working dev branch)\n", " 2. [scikit-image](http://scikit-image.org/)\n", " 3. [pyparty](https://github.com/hugadams/pyparty) (for some multiplot utilities)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Loading some people" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "I used facebook to track the URL to some pictures of my friends, with unobstructed views of their faces and seemingly good image quality. Then I grabbed a bunch of individual and group pics of celebrities. \n", "\n", "
\n", "*The links to my friends are hidden for privacy...*" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "%pylab inline\n", "from __future__ import division\n", "import skimage.io as skio\n", "\n", "# Change matplotlib label fontsize\n", "from matplotlib import rcParams\n", "rcParams['font.size'] = 15\n", "\n", "BUDDIES = dict(ME = 'https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xap1/v/t1.0-9/970276_643330279472_1364386421_n.jpg?oh=ef0a6a5758cee5ddccd1eb951937916f&oe=557FFA87&__gda__=1434357290_1745bc5628ade9870d78c55c661b4046',',\n", " LOVELY_FIANCE ='