The Trueface Developer Hub

Welcome to the Trueface developer hub. You'll find comprehensive guides and documentation to help you start working with Trueface as quickly as possible, as well as support if you get stuck. Let's jump right in!

Simple High Availability setup

If you want to load balance your HTTP requests to our REST API across multiple nodes you can base your setup off of this very simple configuration example. This is meant as a starting point since your architecture might have more specific requirements.

Create a shared file volume on the docker host machine

docker volume create collections

Start 4 trueface nodes mapped to a different port each

docker run -dit -p 8085:8080 \
    --name trueface_tfv3cpu1 \
    --mount source=collections,target=/collections trueface/tfv3-cpu
    
docker run -dit -p 8086:8080 \
    --name trueface_tfv3cpu2 \
    --mount source=collections,target=/collections trueface/tfv3-cpu
    
docker run -dit -p 8087:8080 \
    --name trueface_tfv3cpu3 \
    --mount source=collections,target=/collections trueface/tfv3-cpu
    
docker run -dit -p 8088:8080 \
    --name trueface_tfv3cpu4 \
    --mount source=collections,target=/collections trueface/tfv3-cpu

Copy over your credentials file

docker cp creds.json trueface_tfv3cpu1:/
docker cp creds.json trueface_tfv3cpu2:/
docker cp creds.json trueface_tfv3cpu3:/
docker cp creds.json trueface_tfv3cpu4:/

Start the app

docker exec -dit trueface_tfv3cpu1 sh -c 'pm2 start app'
docker exec -dit trueface_tfv3cpu2 sh -c 'pm2 start app'
docker exec -dit trueface_tfv3cpu3 sh -c 'pm2 start app'
docker exec -dit trueface_tfv3cpu4 sh -c 'pm2 start app'

You now have 4 Trueface Vision Box nodes up and running!

Let's make this HA!

Install nginx on your host machine, the one that is running the docker containers

sudo apt install -y nginx jq

Configure NginX for load balancing

Use the following configuration in /etc/nginx/sites-enabled/default

upstream trueface {
    server 0.0.0.0:8085;
    server 0.0.0.0:8086;
    server 0.0.0.0:8087;
    server 0.0.0.0:8088;
}

server {
	listen 80 default_server;
	listen [::]:80 default_server;

	# add your SSL configuration here
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/html;

	server_name _;

	location / {
            proxy_pass http://trueface;
        }
}

Reload NginX

sudo service nginx reload

You are done! Let's test this!

Enroll a new image in a collection

# let's get some images
curl -s https://pbs.twimg.com/profile_images/704366711739387904/dBlzfG_S_400x400.jpg > enroll_george.jpg
curl -s https://www.etonline.com/sites/default/files/styles/max_1280x720/public/images/2013-05/640_george_clooney_20130120_159272928.jpg > identify_george.jpg

# make sure you have your creds.json file in the same
# directory you are running this command
curl \
	-H "content-type: application/json" \
	--data "{ \"namespace\": \"celebrities\", \"collection_id\": \"actors\", \"label\": \"George\", \"image\": { \"data\": \"$(base64 -w0 enroll_george.jpg)\" } }" \
  localhost:80/enroll
{"execution_time": 0.6958839893341064,
 "message": "match performed succesfully",
 "data": "xbIsveWT... <long base64 string truncated>",
 "success": true}

If you look at the filesystem on each node, you will see the collection getting created or updated.
The collection is located on the shared volume we mounted when we created the container so it will be updated across all your nodes.

docker exec -it trueface_tfv3cpu1 sh -c 'find /collections'
/collections
/collections/celebrities
/collections/celebrities/actors.npz

Identify an image

curl \
	-H "content-type: application/json" \
	--data "{ \"namespace\": \"celebrities\", \"collection_id\": \"actors\", \"image\": { \"data\": \"$(base64 -w0 identify_george.jpg)\" } }" \
  localhost:80/identify
{"execution_time": 2.1204941272735596, 
 "message": "Identify preformed successfully successfully", 
 "data": [{
       "confidence": 0.6769804316535968, 
       "predicted_label": "George", 
       "bounding_box": [393.3023436367512, 125.14740616083145, 771.620245963335, 659.4643105119467, 0.9999953508377075]}, 
 "success": true}

Updated about a month ago

Simple High Availability setup


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.