Skip to content

This repository contains the code for the paper LDFA: Latent Diffusion Face Anonymization for Self-driving Applications

License

Notifications You must be signed in to change notification settings

KIT-MRT/latent_diffusion_face_anonymization

Repository files navigation

Latent Diffusion Face Anonymisation LDFA

This repository contains the code for the paper LDFA: Latent Diffusion Face Anonymization for Self-driving Applications.

Structure

Dockerfile

The dockerfile is used to start container which runs the Automatic1111 web UI for stable diffusion. LDFA uses the API to conveniently use a stable diffusion model for the anonymization of human faces.

Scripts

detect_faces.py - This script uses RetinaFace to detect faces on a given dataset.
face_anonymization.py - This script implements different functions for face anonymization.
body_anonymization.py - This script implements different functions for body anonymization.

Test

The tests are not meant to be used as a unit test, but to show a quick script usage of our tooling. The tests are run on some samples from the cityscapes dataset.

Usage

Anaconda

First setup the anaconda environment
conda create -n ldfa python=3.10
then install pytorch with the correct cuda version:
conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=11.8 -c pytorch -c nvidia and xformers
pip install xformers==v0.0.23.post1 --index-url https://download.pytorch.org/whl/cu118. After this you need to install all necessary dependencies and the module itself with
pip install -r requirements.txt && python setup.py install

The stable diffusion interface is not included in the anaconda environment. You can use the docker container to run the stable diffusion interface.

Docker

First build the docker image with

docker build -t ldfa .

Then you can run the docker container with

docker run -p 7860:7860 ldfa 

Face Anonymization

Once the docker container is running you can generate masks using:

python3 detect_faces.py --image_dir=/data/images --mask_dir=/data/masks

and anonymize the detected faces using:

python3 face_anonymization.py --image_dir=/data/images --mask_dir=/data/masks --output_dir=/data/anonymized --anon_function lda

You can also use the other anonymization functions implemented. See python3 face_anonymization.py --help for more functions.

Body Anonymization

The body anonymization works similar to the face anonymization. You can use the body_anonymization.py script to anonymize the bodies.

python3 body_anonymization.py --image_dir=/data/images --output_dir=/data/anonymized --anon_function lda

This script uses YoloV8 to generate the masks for the persons to be anonymized.

You can also use the other anonymization functions implemented. See python3 body_anonymization.py --help for more functions.

Citation

If you are using LDFA in your research, please consider to cite us.

@InProceedings{Klemp_2023_CVPR,
    author    = {Klemp, Marvin and R\"osch, Kevin and Wagner, Royden and Quehl, Jannik and Lauer, Martin},
    title     = {LDFA: Latent Diffusion Face Anonymization for Self-Driving Applications},
    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops},
    month     = {June},
    year      = {2023},
    pages     = {3198-3204}
}

About

This repository contains the code for the paper LDFA: Latent Diffusion Face Anonymization for Self-driving Applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published