How to configure multiple instances of Facebox

Machina
Machine Box
Published in
3 min readOct 19, 2017

With Facebox (using a simple http API) you can do face detection and recognition on your own data. For example, you can stream a webcam to Facebox to recognize people live, or process video or still image files at scale.

Facebox can be taught to recognize any number of people. To do so, you have to invoke /facebox/teach with a name,id and an image with a single face in it. You only need one photo per person. After you’ve taught Facebox with the people you want it to recognize, you can start recognizing faces by invoking the /facebox/check endpoint.

Try it in 5 minutes by downloading Facebox and teaching it to recognize the Beatles

Saving and restoring the state for one box

By design, all the teaching you might do in a session is stored in memory, so when the container stops you lose all of that data.

Even if all the data is in memory, teaching around 5000 faces would fill just 10MB of RAM

To save all of the teaching, you can create a state file:

You can then use that same state file to restore the teaching to an instance of Facebox:

Tip: Tagbox works exactly the same way.

Using multiple instances of Facebox

Given that we don’t restrict the use of Facebox, you can have as many instances of Facebox as you want. But how do I share the state across multiple instances?

To be able to share the state, you can put the state file into a web server and access it from a URL. For example, let’s say that we teach Facebox to recognize certain celebrities all in one machine, and now we would like to share the celebrity recognition model with multiple machines so we can scale horizontally.

The only thing that we need to do is use an environment variable MB_FACEBOX_STATE_URL and point that variable to the URL where the state file lives.

When Facebox starts up, it will download the file from the URL, and load it into the box.

What if I have to add more faces?

If you need to add more faces, you can just do the teaching as normal, and save the state again. Once you have the new state file, you can upload it to the same URL. If you set the environment variableMB_FACEBOX_STATE_POLL_SECONDS, Facebox would poll the URL looking for changes on the http headers ETag or Last-Modified, and if there is a more recent file, Facebox would download the file and update the state. There is no need for reboots.

Is there any other way to synchronise and persist the state of teaching?

For PRO costumers we enabled a simple way to persist and synchronise the state of teaching with multiple Facebox instances using Redis server. After setting up some environment variables, you will be able to transparently use the same state with multiple instances by just setting up a Redis server.

Stay in touch, for questions and feedback

We are always building new boxes and features, and usually take our priority list from developer feedback, so get involved.

--

--

Machina
Machine Box

I'm Machina - the mascot for Machine Box. Add machine learning features to your applications. Production ready Docker containers that you can deploy and scale.