You may have noticed that I’m studying Machine Learning (including Deep Learning). In my study I like to implement codes from other developers or create some codes from scratch. If you also study about facial recognition you may have heard about Facenet. Facenet is a Tensorflow implementation for face recognition that you can integrate into your projects, and I used it to create my Face Recognition API.
In this first article, you will learn how to use my facial recognition API with an OCI Compute instance (Ubuntu 16.04). You can choose between CPU or GPU instances, but if you have multiple photos of different people, I recommend GPU instances to speed up training for your model.
In the second article, you’ll learn how to integrate it with OCI Object Storage to store all your images.
First of all, some of your account information is required.
Access your Oracle Cloud account, copy and paste your user OCID into a notepad.
Create a new API Key for your user using this public key.
-----BEGIN PUBLIC KEY-----
-----END PUBLIC KEY-----
Copy and paste the fingerprint generated.
Copy and paste your tenancy OCID.
Copy and paste your compartment OCID.
Open a terminal, access your OCI Compute instance and install the required libraries.
$ sudo apt-get update -y $ sudo apt-get install -y libsm6 libxext6 libxrender-dev ffmpeg
Clone my project from GitHub.
$ git clone https://github.com/waslleysouza/face_recognition_api.git
Create a new environment using Anaconda.
$ conda create -n facerec python=3.6 -y
Activate your environment.
$ source activate facerec
Access the project folder.
$ cd face_recognition_api
Install the required python packages using the requirements.txt file.
- If your instance has only CPU, run:
$ pip install -r requirements-cpu.txt
- If your instance has a GPU, run:
$ pip install -r requirements-gpu.txt
Open the config/config.prod file.
$ vi config/config.prod
Edit and save the file.
- user: The user’s OCID
- fingerprint: The fingerprint generated above
- key_file: The private key of public key. If you used my public key to generate a new fingerprint, use the “./config/oci_api_key_private.pem” file
- tenancy: The Tenancy’s OCID
- region: The region of your compartment
- compartment: The compartment’s OCID
Start the application in background.
$ nohup python server.py &
Open your browser and go to the Facial Recognition API Console.
The Face Recognition API has 4 opertions:
- ADD: This operation adds a new human face to the Face Recognition API database. You can upload videos or images that contain only one person.
- CLASSIFY: This operation executes a face recognition. You can upload images that contains only one person.
- TRAIN: This operation trains the model to recognize the new faces added by the ADD operation.
- RESTART: This operation reloads the Face Recognition API model if you experience any problems.
Go to the ADD operation and upload your photo.
Then go to the TRAIN operation to train the model with your face.
Wait for 15 seconds and perform the CLASSIFY operation.
Use a different photo of you and the API will try to recognize.
If you’re lucky, the API will recognize you! = D
Machine Learning is magic!
In this first article, you learned how to install and run my Face Recognition API in OCI. In the second article, you’ll learn how to integrate it with OCI Object Storage to store all your images.
Have a good time!