Scala implementation of the understand.ai Anonymizer
You have two solutions to download models:
You have to put both models in the folder /src/main/resources/models with the following names:
- face.pb: detection model for face
- plate.pb: detection model for plate
To use Tensorflow for Scala, you need to install the Protocol Buffers compiler (at least version 3).
With apt: apt-get install protobuf-compiler
With brew: brew install protoc
Feel free to check this link for more information.
Anonymization allows you to blur face and plate to improve the privacy of each other. See an exemple below of an image presenting several cars and faces before and after anonymization.
Four important steps to anonymize our images:
- First of all, we use Tensorflow Scala to detect plates and faces.
- We create a mask with image size. This mask is the area who need to be blurred.
- We use a convolution with gaussian kernel and our image to blur everything.
- Using our previous mask we keep only the detection boxes area blurred and all other parts as initial.
In addition, we use a mean kernel to have smooth border around the blurred area.
There are multiple options to run the anonymizer.
For the documentation, please use: --help
.
Name | Value | Required |
---|---|---|
--input |
Path to the input folder | X |
--output |
Path to the output folder | X |
--image-extensions |
Comma-separated list of file types that will be anonymized (e.g. jpg, png) | |
--face-threshold |
Detection confidence needed to anonymize a detected face. Must be in [0.001, 1.0] | |
--plate-threshold |
Detection confidence needed to anonymize a license plate. Must be in [0.001, 1.0] | |
--kernel-size |
Size of the gaussian kernel. Must be odd | |
--sigma |
Standard deviation. | |
--box-kernel-size |
Size of the kernel used to smooth transitions. Must be odd |
Inside the root folder, use sbt assembly
.
Once you have built your jar, use java -jar <name_of_your_jar> <options>
Otherwise, if you want to test quickly, in the root folder, you can use sbt "run --input <inputPath> --output <outputPath>"
As said in the initial python project:
"An image for one of the test cases was taken from the COCO dataset. The pictures in this README are under an Attribution 4.0 International license."