The Network is the Computer: You can’t hide your face from the Cloud any more

I’ve been moving into Cloud-based services, and I’m so impressed with Microsoft’s Cognitive Services. For this I’ve integrated to a speech…

The Network is the Computer: You can’t hide your face from the Cloud any more

I’ve been moving into Cloud-based services, and I’m so impressed with Microsoft’s Cognitive Services. For this I’ve integrated to a speech API and now integrating their face API. The service returns a JSON string which outlines parameters such as age, gender, glasses, and smile. Let’s try it on Theresa May [here]:

And David Cameron [here]:

and it detects Nicolia’s smile [here]:

And beards are detected [here]:

Here’s my basic code (you need to use your own key — YOUR KEY). With this we use an HTTP post to pass the URI for the image, and return the JSON string:

import sys
import json
import urllib
import requests
from pprint import pprint
url ='http://asecuritysite.com/log/F52361.jpg'

headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': 'YOUR KEY',
}
params = urllib.urlencode({
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses',
})
body = {
'url': url
}
url = 'https://westeurope.api.cognitive.microsoft.com/face/v1.0/detect?%s' % params
resp = requests.post(url, data=json.dumps(body), headers=headers)

binary = resp.content
pprint (binary)
output = json.loads(binary)
print 'Face ID: ',output[0]['faceId']
print 'Face Rectangle: ',output[0]['faceRectangle']
print 'Age: ',output[0]['faceAttributes']['age']
print 'Gender: ',output[0]['faceAttributes']['gender']
print 'Smile: ',output[0]['faceAttributes']['smile']
print 'Glasses: ',output[0]['faceAttributes']['glasses']
print 'Facial Hair: ',output[0]['faceAttributes']['facialHair']
print 'Head Pose: ',output[0]['faceAttributes']['headPose']

You create your key in the Azure Cloud:

Conclusions

We used to integrate DLLs, but the future is Cloud Services. But remember you need a network to actually use them, so make sure you have some resilience.