Lambda Labs Face Recognition API Introduction
We hate long and boring documentation too. Let's skip right to the code examples (the full documentation starts below the horizontal line). So here's facial recognition in just Four Easy Steps.
Step 0. Sign up for the API
Sign Up to Our Facial Recognition API
Step 1. Create an Album
An album is a set of tagged images that can be used to recognize new ones. Let's instantiate an api and create an album. (Album names are globally unique, so you'll have to choose something other than 'Presidents'.)
from FaceRecognition import FaceRecognition
api = FaceRecognition("YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY")
# create an album 'Presidents' and save album_key
album = "Presidents"
album_key = api.createAlbum(album).body['albumkey']
Step 2. Train the Album
Give the album a few labeled images to work with. The more images you give it, the more accurate the model will be. Note, you can give us either urls or files.
# train the 'bush' label (two urls and one file)
api.trainAlbum(album, album_key, 'bush', None, "http://lambdal.com/bush/0.jpg") # using variable arguments
api.trainAlbum(album, album_key, 'bush', urls="http://lambdal.com/bush/1.jpg") # using kwargs
api.trainAlbum(album, album_key, 'bush', files=open("bush2.jpg"))
...
# train the 'clinton' label (using all files [but two ways to call it])
api.trainAlbum(album, album_key, 'clinton', open("clinton1.jpg"))
api.trainAlbum(album, album_key, 'clinton', open("clinton2.jpg"))
api.trainAlbum(album, album_key, 'clinton', files=open("clineton3.jpg"))
...
Step 3. Rebuild the Album
Tell the album to build a model itself using the labeled images.
# rebuild the album after training api.rebuildAlbum(album, album_key)
Step 4. Recognize an Image
Give the album an image to recognize. You can see that there are two options, urls and files.
# run recognition using a url
link_response = api.recognize(album, album_key, urls="http://lambdal.com/clinton/19.jpg")
# run recognition using a file upload
file_response = api.recognize(album, album_key, files=open("clinton.jpg"))
print("Bill Clinton was classified as:")
print(link_response.body['photos'][0]['tags'][0]['uids'])
<!---------------------- Begin Boring Full Docs ---------------------->
1. Sign Up
Select a plan to access our API.
Create an account
2. Get Keys
Log in at mashape.com and get your public and private keys.
3. Download Client
Download the Lambda Labs Face API Client from mashape
4. Code Examples
Use the newly downloaded client
Here are some code samples:
Detect
-
from FaceRecognition import FaceRecognition api = FaceRecognition("MY_PUBLIC_KEY", "MY_PRIVATE_KEY") # File Upload api.detect(files=open("~/Desktop/face.jpg")) # Url Link api.detect(urls="http://lambdal.com/test2.jpg") -
require File.join(File.dirname(__FILE__), "FaceRecognition.rb") api = FaceRecognition.new("MY_PUBLIC_KEY", "MY_PRIVATE_KEY") # File Upload: api.detect(File.open("/Users/sabalaba/Downloads/jennifer.jpg")) # URL link: api.detect(nil, "http://lambdal.com/tiger.jpg") -
require_once("FaceRecognition.php"); $obj = new FaceRecognition("MY_PUBLIC_KEY", "MY_PRIVATE_KEY"); // File Upload $obj->detect(fopen("~/Desktop/face.jpg", "r"), NULL); // URL Link $obj->detect(NULL, "http://lambdal.com/test2.jpg"); -
import FaceRecognition; import java.io.File; // and when you are ready to use it just create a new instance! FaceRecognition client = new FaceRecognition("MY_PUBLIC_KEY", "MY_PRIVATE_KEY"); client.detect(new File("~/Desktop/face.jpg"), null);
Recognize
-
from FaceRecognition import FaceRecognition api = FaceRecognition("MY_PUBLIC_KEY", "MY_PRIVATE_KEY") # create an album and save album_key album = "Presidents" album_key = api.createAlbum(album).body['albumkey'] print "Got Album Key: ", album_key # train the bush label api.trainAlbum(album, album_key, 'bush', urls="http://lambdal.com/bush/0.jpg") api.trainAlbum(album, album_key, 'bush', urls="http://lambdal.com/bush/1.jpg") api.trainAlbum(album, album_key, 'bush', urls="http://lambdal.com/bush/2.jpg") ... # train the clinton label api.trainAlbum(album, album_key, 'clinton', urls="http://lambdal.com/clinton/0.jpg") api.trainAlbum(album, album_key, 'clinton', urls="http://lambdal.com/clinton/1.jpg") api.trainAlbum(album, album_key, 'clinton', urls="http://lambdal.com/clinton/2.jpg") ... # rebuild the album after training api.rebuildAlbum(album, album_key) # run recognition on a new image link_response = api.recognize(album, album_key, urls="http://lambdal.com/clinton/19.jpg") file_response = api.recognize(album, album_key, files=open("clinton.jpg")) print("Bill Clinton was classified as:") print(link_response.body['photos'][0]['tags'][0]['uids']) -
require File.join(File.dirname(__FILE__), "FaceRecognition.rb") api = FaceRecognition.new("MY_PUBLIC_KEY", "MY_PRIVATE_KEY") # Create an album and save the album key album = "Presidents" album_key = api.createAlbum(album).body['albumkey'] print "Got Album Key: ", album_key, "\n" # train the bush label api.trainAlbum(album, album_key, 'bush', nil, "http://lambdal.com/bush/0.jpg") api.trainAlbum(album, album_key, 'bush', nil, "http://lambdal.com/bush/1.jpg") api.trainAlbum(album, album_key, 'bush', nil, "http://lambdal.com/bush/2.jpg") ... # train the clinton label api.trainAlbum(album, album_key, 'clinton', nil, "http://lambdal.com/clinton/0.jpg") api.trainAlbum(album, album_key, 'clinton', nil, "http://lambdal.com/clinton/1.jpg") api.trainAlbum(album, album_key, 'clinton', nil, "http://lambdal.com/clinton/2.jpg") ... # rebuild the album after training api.rebuildAlbum(album, album_key) # run recognition on a new image link_response = api.recognize(album, album_key, nil, "http://lambdal.com/clinton/19.jpg") file_response = api.recognize(album, album_key, File.open("clinton.jpg"))
5. Current & Upcoming Functionality
Available Now:
- Face Detection
- Face Feature Extraction
- Eyes
- Nose
- Mouth
- Gender Classification
- Face Recognition
6. Support
If you have any more questions, feedback, or need help integrating, please don't hesitate to reach out:
Email: s@lambdal.com