Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Google Colab demo notebook #33

Merged
merged 6 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add Feature to Use Config Files by @AjinkyaIndulkar in https://github.com/sensity-ai/dot/pull/17
- Add Github Templates by @AjinkyaIndulkar in https://github.com/sensity-ai/dot/pull/16
- Add contributors list by @AjinkyaIndulkar in https://github.com/sensity-ai/dot/pull/31
- Add Google Colab demo notebook by @AjinkyaIndulkar https://github.com/sensity-ai/dot/pull/33

#### Updated

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
[![build-dot](https://github.com/sensity-ai/dot/actions/workflows/build_dot.yaml/badge.svg)](https://github.com/sensity-ai/dot/actions/workflows/build_dot.yaml)
[![code-check](https://github.com/sensity-ai/dot/actions/workflows/code_check.yaml/badge.svg)](https://github.com/sensity-ai/dot/actions/workflows/code_check.yaml)

<br>

<a href="https://colab.research.google.com/github/sensity-ai/dot/blob/main/notebooks/colab_demo.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" height=20></a>

</div>

*dot* (aka Deepfake Offensive Toolkit) makes real-time, controllable deepfakes ready for virtual cameras injection. *dot* is created for performing penetration testing against e.g. identity verification and video conferencing systems, for the use by security analysts, Red Team members, and biometrics researchers.
Expand Down
Binary file added data/test_video.mp4
Binary file not shown.
14 changes: 7 additions & 7 deletions docs/run_without_camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ dot \
--use_gpu
```

## Faceswap images from directory(Simswap)
## Faceswap images from directory (Simswap)

You can pass a `--source` folder with images and some `--target` images. Faceswapped images will be generated at `--save_folder` including a metadata json file.

```bash
python image_swap.py \
python scripts/image_swap.py \
--config <path_to_config/config.yaml> \
--source <path_to_source_images_folder> \
--target <path_to_target_images_folder> \
--save_folder <output_dir> \
--limit 100
```

## Faceswap images from metadata
## Faceswap images from metadata (SimSwap)

```bash
python metadata_swap.py \
python scripts/metadata_swap.py \
--config <path_to_config/config.yaml> \
--local_root_path <path_to_root_directory> \
--metadata <path_to_metadata_file> \
Expand All @@ -48,11 +48,11 @@ python metadata_swap.py \
--limit 100
```

## Faceswap on video files
## Faceswap on video files (SimSwap)

```bash
python video_swap.py \
-c <path_to_config/config.yaml> \
python scripts/video_swap.py \
-c <path_to_simpswap_config/config.yaml> \
-s <path_to_source_images> \
-t <path_to_target_videos> \
-o <path_to_output_folder> \
Expand Down
212 changes: 212 additions & 0 deletions notebooks/colab_demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Deepfake Offensive Toolkit\n",
"\n",
"> **Disclaimer**: This notebook is primarily used for demo purposes on Google Colab.\n",
"\n",
"**Note**: We recommend running this notebook on Google Colab with GPU enabled.\n",
"\n",
"To enable GPU, do the following: \n",
"\n",
"`Click \"Runtime\" tab > select \"Change runtime type\" option > set \"Hardware accelerator\" to \"GPU\"`\n",
"\n",
"### Install Notebook Pre-requisites:\n",
"\n",
"We install the following pre-requisities:\n",
"- `ffmpeg`\n",
"- `conda` (via [condacolab](https://github.com/conda-incubator/condacolab))\n",
"\n",
"Note: The notebook session will restart after installing the pre-requisites. \n",
"\n",
"**RUN THE BELOW CELL ONLY ONCE.**\n",
"\n",
"**ONCE THE NOTEBOOK SESSION RESTARTS, SKIP THIS CELL MOVE TO \"STEP 1\" SECTION OF THIS NOTEBOOK**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# install linux pre-requisites\n",
"!sudo apt install ffmpeg\n",
"\n",
"# install miniconda3\n",
"!pip install -q condacolab\n",
"import condacolab\n",
"condacolab.install_miniconda()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 1 - Clone Repository"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"os.chdir('/content')\n",
"CODE_DIR = 'dot'\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!git clone https://github.com/sensity-ai/dot.git $CODE_DIR\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"os.chdir(f'./{CODE_DIR}')\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 2 - Setup Conda Environment"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# update base conda environment: install python=3.8 + cudatoolkit=11.3\n",
"!conda install python=3.8 cudatoolkit=11.3\n",
"\n",
"# install pip requirements\n",
"!pip install llvmlite==0.36.0 onnxruntime-gpu==1.9.0\n",
"!pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113\n",
"!pip install -r requirements.txt\n",
"\n",
"# install dot\n",
"!pip install -e .\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 2 - Download Pretrained models"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# download binaries\n",
"! wget https://github.com/sensity-ai/dot/releases/download/1.0.0/dot_model_checkpoints.z01 \\\n",
"&& wget https://github.com/sensity-ai/dot/releases/download/1.0.0/dot_model_checkpoints.z02 \\\n",
"&& wget https://github.com/sensity-ai/dot/releases/download/1.0.0/dot_model_checkpoints.zip\n",
"\n",
"# unzip binaries\n",
"! zip -s 0 dot_model_checkpoints.zip --out saved_models.zip \\\n",
"&& unzip saved_models.zip\n",
"\n",
"# clean-up\n",
"!rm -rf *.z*\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 3: Run dot on image and video files instead of camera feed\n",
"\n",
"### Using SimSwap on Images\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!dot \\\n",
"-c ./configs/simswap.yaml \\\n",
"--target \"data/\" \\\n",
"--source \"data/\" \\\n",
"--save_folder \"image_simswap_output/\" \\\n",
"--use_image \\\n",
"--use_gpu\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using SimSwap on Videos"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!python scripts/video_swap.py \\\n",
"-s \"data/\" \\\n",
"-t \"data/\" \\\n",
"-o \"video_simswap_output/\" \\\n",
"-d 5 \\\n",
"-l 5\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [],
"name": "colab_demo.ipynb",
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}