Giter VIP home page Giter VIP logo

anonymizer's Introduction

This is a fork that implements a docker entrypoint

Usage:

CPU

docker build -t anonymizer -f Dockerfile .

docker run --rm -v /Users/Marius/Documents/DEV/anonymizer/weights:/weights -v /Users/Marius/Documents/DEV/anonymizer/images:/input -v /Users/Marius/Documents/DEV/anonymizer/images/out:/output anonymizer --input /input --image-output /output --weights /weights/ --obfuscation-kernel 47,1,9 --no-write-detections

GPU

First install nvidia-runtime for docker, see: https://stackoverflow.com/questions/59008295/add-nvidia-runtime-to-docker-runtimes

The nvidia runtime you need, is nvidia-container-runtime.

Follow the installation instructions here: https://github.com/NVIDIA/nvidia-container-runtime#installation

Basically, you install it with your package manager first, if it's not present:

sudo apt-get install nvidia-container-runtime

Then you add it to docker runtimes: https://github.com/nvidia/nvidia-container-runtime#daemon-configuration-file

This option worked for me:

$ sudo tee /etc/docker/daemon.json <<EOF
{
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}
EOF
sudo pkill -SIGHUP dockerd

Check that it's added:

$ docker info|grep -i runtime
 Runtimes: nvidia runc
 Default Runtime: runc

Build with

docker build -t anonymizer -f DockerfileGPU .

Run with

docker run --runtime nvidia --rm -v /home/marius/PycharmProjects/anonymizer/weights:/weights -v /home/marius/PycharmProjects/anonymizer/images:/input -v /home/marius/PycharmProjects/anonymizer/images/out:/output anonymizer --input /input --image-output /output --weights /weights/ --obfuscation-kernel 47,1,9 --no-write-detections

docker run --gpus all --rm -v /home/marius/PycharmProjects/anonymizer/weights:/weights -v /home/marius/PycharmProjects/anonymizer/images:/input -v /home/marius/PycharmProjects/anonymizer/images/out:/output anonymizer --input /input --image-output /output --weights /weights/ --obfuscation-kernel 47,1,9 --no-write-detections

Alternative use:

Disable image blurring with --no-write-images and blur them using box coordinates and imagemagick command : convert a.png -region 150x150+599+261 -blur 0x100 +region b.png See: https://legacy.imagemagick.org/Usage/masking/#region_warping and https://stackoverflow.com/questions/47064408/blur-part-of-image-in-imagemagick

Or

If you already have a bounding box for the license plate, you may use the following Python code to blur the area.

from PIL import Image, ImageFilter

path = 'vehicle.jpg'
for res in [dict(box=dict(xmin=10, ymin=10, xmax=100, ymax=100))]:
    box = res['box']
    crop_box = (box['xmin'], box['ymin'],
                box['xmax'], box['ymax')
    im = Image.open(path)
    ic = im.crop(crop_box)
    blur_image = ic.filter(ImageFilter.GaussianBlur(radius=5))
    im.paste(blur_image, crop_box)
    im.save('blurred-number-plate.jpg')

understand.ai Anonymizer

To improve privacy and make it easier for companies to comply with GDPR, we at understand.ai decided to open-sourcing our anonymization software and weights for a model trained on our in-house datasets for faces and license plates.
To make it easy for everyone to use these weights in their own projects the model is trained with Tensorflow Object Detection API.

Our anonymizer is used for projects with some of Germany's largest car manufacturers and suppliers, but we are sure there are many more applications.
We are looking forward to a widespread use and would love to hear your feedback.
Feel free to contact us with any questions at [email protected].

Disclaimer

Note that the version here is not identical to the anonymizer we use with our customers. The models are fairly similar, but the glue-code is written for easy-of-use instead of speed.
For this reason no multiprocessing code or batched detection and blurring are used in this repository.

This version of our anonymizer is trained to detect faces and license plates in images recorded with sensors that are typically used in autonomous vehicles. It will not work on low-quality or grayscale images and will also not work on fish-eye or other extreme camera configuration. If there is high demand for models specialised for certain camera configurations, we might decide to open-source our more specialised models as well.

Examples

License Plate Example Raw License Plate Anonymized

Face Example Raw Face Example Anonymized

Installation

To install the anonymizer just clone this repository, create a new python3.6 environment and install the dependencies.
The sequence of commands to do all this is

python -m venv ~/.virtualenvs/anonymizer
source ~/.virtualenvs/anonymizer/bin/activate

git clone https://github.com/understand-ai/anonymizer
cd anonymizer

pip install --upgrade pip
pip install -r requirements.txt

To make sure everything is working as intended run the test suite with the following command

pytest

Running the test cases can take several minutes and is dependent on your GPU (or CPU) and internet speed.
Some test cases download model weights and some perform inference to make sure everything works as intended.

Usage

In case you want to run the model on CPU, make sure that you install tensorflow instead of tensorflow-gpu listed in the requirements.txt.

Since the weights will be downloaded automatically all that is needed to anonymize images is to run

PYTHONPATH=$PYTHONPATH:. python anonymizer/bin/anonymize.py --input /path/to/input_folder --image-output /path/to/output_folder --weights /path/to/store/weights

from the top folder of this repository. This will save both anonymized images and detection results as json-files to the output folder.

Advanced Usage

In case you do not want to save the detections to json, add the parameter no-write-detections. Example:

PYTHONPATH=$PYTHONPATH:. python anonymizer/bin/anonymize.py --input /path/to/input_folder --image-output /path/to/output_folder --weights /path/to/store/weights --no-write-detections

Detection threshold for faces and license plates can be passed as additional parameters. Both are floats in [0.001, 1.0]. Example:

PYTHONPATH=$PYTHONPATH:. python anonymizer/bin/anonymize.py --input /path/to/input_folder --image-output /path/to/output_folder --weights /path/to/store/weights --face-threshold=0.1 --plate-threshold=0.9

By default only *.jpg and *.png files are anonymized. To for instance only anonymize jpgs and tiffs, the parameter image-extensions can be used. Example:

PYTHONPATH=$PYTHONPATH:. python anonymizer/bin/anonymize.py --input /path/to/input_folder --image-output /path/to/output_folder --weights /path/to/store/weights --image-extensions=jpg,tiff

The parameters for the blurring can be changed as well. For this the parameter obfuscation-kernel is used. It consists of three values: The size of the gaussian kernel used for blurring, it's standard deviation and the size of another kernel that is used to make the transition between blurred and non-blurred regions smoother.

With the default blurring parameters ( --obfuscation-kernel 21,2,9), large size plates in the foreground are not sufficiently blurred. The size of the gaussian kernel must be increased significantly to get good results. I got good results with --obfuscation-kernel 47,1,9

Example usage:

PYTHONPATH=$PYTHONPATH:. python anonymizer/bin/anonymize.py --input /path/to/input_folder --image-output /path/to/output_folder --weights /path/to/store/weights --obfuscation-kernel="65,3,19"

Attributions

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. You can find the pictures here and here.

anonymizer's People

Contributors

blaues0cke avatar mariusmez avatar rorph avatar seb-uai avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.