This repository provides an OpenFaaS function to remove faces on pictures thanks to online machine learning service called MachineBox.
Input | Output | Output with blur effect |
---|---|---|
-
You need the OpenFaas CLI to build and deploy the function. So, first of all, you need to download it.
curl -sL https://cli.openfaas.com | sudo sh
-
This function is based on a MachineBox service called FaceBox. You can host your own facebox server with
docker run -p 8081:8080 -e "MB_KEY=${MB_KEY}" machinebox/facebox
. No worry, I already added this service for you in the OpenFaaS stack 👍 .By the way, you still have to get your own MachineBox key. Just sign in on MachineBox.
-
Set your MachineBox key as environment variable :
MB_KEY="ThIsIsThEKeYiGeTfRoMhTtPs://mAcHiNeBoX.Io/aCcOuNt"
-
Init your docker swarm cluster :
docker swarm init
-
Deploy the OpenFaaS stack (embedded machinebox service on port 8081) :
MB_KEY=${MB_KEY} docker stack deploy func --compose-file docker-compose.yml
-
Build the anonymizer function :
./build_all.sh
-
Deploy the function on OpenFaaS :
faas-cli deploy -f func_facebox.yml
I arbitrary chose this picture for the test (first Google Images item for keyword people):
-
On you browser (http://localhost:8080), you should get something like :
-
Press Invoke button! Your anonymized picture is downloading.
-
Open your anonymized picture with your favorite image viewer ! That rocks !
Because OpenFaaS provides a REST API, you can invoke this function programmatically :
URL="http://epilepsyu.com/wp-content/uploads/2014/01/happy-people-1050x600.jpg"
curl http://localhost:8080/function/anonymize -d "${URL}" > example_anonymized_people_curl.jpg
docker stack rm func
docker swarm leave --force
If you want to use another FaceBox server url, simply change the facebox environment variable in file func_facebox.yml to fit with yours.
functions:
anonymize:
lang: Dockerfile
handler: ./faas_anonymizer
image: functions/faas_anonymizer:latest
environment:
facebox: https://myFaceBoxServer
Remove faces is too much for you ? Why not just blur the people ? Just set the environment effect to blur, or simply use the blur function I added for you.
functions:
blur:
lang: Dockerfile
handler: ./faas_blur
image: functions/faas_blur:latest
environment:
facebox: http://localhost:8081
effect: blur
This challenge was given on Twitter :
The function source code is strongly inspired from this MachineBox blog post.
For more details about Machine Box.
For more details about OpenFaaS.
Give this repository a star (because it's my first golang function hack) :