hukkelas / DeepPrivacy
- среда, 18 сентября 2019 г. в 00:21:22
Python
DeepPrivacy: A Generative Adversarial Network for Face Anonymization
DeepPrivacy is a fully automatic anonymization technique for images.
This repository contains the source code for the paper "DeepPrivacy: A Generative Adversarial Network for Face Anonymization", published at ISVC 2019.
The DeepPrivacy GAN never sees any privacy sensitive information, ensuring a fully anonymized image.
It utilizes bounding box annotation to identify the privacy-sensitive area, and sparse pose information to guide the network in difficult scenarios.

DeepPrivacy detects faces with state-of-the-art detection methods.
Mask R-CNN is used to generate a sparse pose information of the face, and DSFD is used to detect faces in the image.

Click here to test it on Google Colab!
If you find this code useful, please cite the following:
@article{hukkelaas2019deepprivacy,
title={DeepPrivacy: A Generative Adversarial Network for Face Anonymization},
author={Hukkel{\aa}s, H{\aa}kon and Mester, Rudolf and Lindseth, Frank},
journal={arXiv preprint arXiv:1909.04538},
year={2019}
}
The FDF dataset will be released at github:hukkelas/FDF
Install the following:
Then, install python packages:
pip install -r docker/requirements.txt
In our experiments, we use docker as the virtual environment.
Our docker image can be built by running:
cd docker/
docker build -t deep_privacy . Then, training can be started with:
nvidia-docker run --rm -it -v $PWD:/app -e CUDA_VISIBLE_DEVICES=1 deep_privacy python -m deep_privacy.train models/default/config.ymlHyperparameters and more can be set through config files, named config.yml.
From our paper, the following config files corresponds to our models
models/default/config.yml: Default 12M parameter model with pose (Max 256 channels in convolutions.)models/no_pose/config.yml: Default 12M parameter model without posemodels/large/config.yml (BEST:): Default 46M parameter model with pose (Max 512 channels in convolutions). If you have the compute power, we recommend to use this model.models/deep_discriminator/config.yml: Default deep discriminator model.For each config file, you can download pre-trained models from the following URLS:
models/default/config.ymlmodels/no_pose/config.ymlmodels/large/config.ymlmodels/deep_discriminator/config.ymlThere are several scripts to perform inference
Every scripts require a path to a config.yml file. In these examples, we use the default model with 256 channels in the generator.
Download Face Detector: Before running inference, we expect that you have downloaded the DSFD face detection model, and place it to the path: deep_privacy/detection/dsfd/weights/WIDERFace_DSFD_RES152.pth.
This can be downloaded from the official repository for DSFD
[Google Drive Link].
Run
python -m deep_privacy.inference.anonymize_folder model/default/config.yml --source_path testim.jpg --target_path testim_anonymized.jpgRun
python -m deep_privacy.inference.anonymize_video model/default/config.yml --source_path path/to/video.mp4 --target_path path/to/video_anonymized.mp4Note: DeepPrivacy is a frame-by-frame method, ensuring no temporal consistency in videos.
Run
python -m deep_privacy.inference.anonymize_wider models/default/config.yml --source_path path/to/Wider/face/dataset --target_path /path/to/output/folder
This expects the source path to include the following folders: WIDER_val and wider_face_split.
python -m deep_privacy.metrics.fid_official.calculate_fid models/default/config.ymlpython deep_privacy/metrics/fid_official/calculate_fid_official.py models/default/fid_images/real models/default/fid_images/fakeWhere the two last arguments are the paths to real and fake images.
NOTE: We use nvidias tensorflow docker container to run the FID code.: nvcr.io/nvidia/tensorflow:19.06-py3
Training your own model is easy. First, download our FDF dataset, and put it under data/fdf.
Then run:
python -m deep_privacy.train models/default/config.ymlAll code is under MIT license, except the following:
Code under deep_privacy/detection: