Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: Run GFPGAN in docker container #103

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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
53 changes: 53 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
**/__pycache__
**/.classpath
**/.dockerignore
# **/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/*Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml

**/.github
**/.gitlab
**/*.gitlab-ci.yml

# vim
**/*.swp
**/*.swo
# Pycharm
**/.idea
# VS Code
**/.vscode
**/.vs
# Spyder
**/.spyproject/
# Jupyter NB Checkpoints
**/.ipynb_checkpoints/
**/.notebook

# venvs
env/
venv/

# database
**/*.sqlite3
**/*.db
**/*.rdb

# Video Samples
*/cameras/video_samples
*.mp4
34 changes: 34 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Docker Build

on:
push:
branches:
- 'master'
pull_request:
branches:
- 'master'

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: mostafaelmenbawy/gfpgan:latest
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM nvidia/cuda:10.0-cudnn7-devel

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends --fix-missing \
# python
python3.8 python3-pip python3-setuptools python3-dev \
# OpenCV deps
libglib2.0-0 libsm6 libxext6 libxrender1 libgl1-mesa-glx \
# c++
g++ \
# others
wget unzip

# Ninja
RUN wget https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip && \
unzip ninja-linux.zip -d /usr/local/bin/ && \
update-alternatives --install /usr/bin/ninja ninja /usr/local/bin/ninja 1 --force

# basicsr facexlib
RUN python3 -m pip install --upgrade pip && \
pip3 install --no-cache-dir torch>=1.7 opencv-python>=4.5 && \
pip3 install --no-cache-dir basicsr facexlib realesrgan

# weights
RUN wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth \
-P experiments/pretrained_models &&\
wget https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth \
-P experiments/pretrained_models

RUN rm -rf /var/cache/apt/* /var/lib/apt/lists/* && \
apt-get autoremove -y && apt-get clean

COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . .
RUN pip3 install .


CMD ["python3", "inference_gfpgan.py", "--upscale", "2", "--test_path", "inputs/whole_imgs", "--save_root", "results"]
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,72 @@ You could improve it according to your own needs.

> python -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 gfpgan/train.py -opt options/train_gfpgan_v1.yml --launcher pytorch

## :whale2: Running GFPGAN in a Docker Container

We provide a docker image of the project for easier installation.

### :wrench: Dependencies and Installation

- [NVIDIA-DOCKER](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html)
- NVIDIA GPU

### Inference

If you want to add new images, follow this convention for directories.
Cropped images in `./inputs/cropped_faces` and
whole images in `./inputs/whole_imgs`

#### v0.1.0 on GPU

Using <https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth>

```sh
nvidia-docker run \
--name gfpgan \
--volume <absolute/path/inputs>:/app/inputs \
--volume <absolute/path/results>:/app/results \
-e BASICSR_JIT=True \
{{ DOCKERHUB_REPOSITORY }}/GFPGAN:latest \
python3 inference_gfpgan.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs --save_root results --arch original --channel 1
```

```sh
nvidia-docker run \
--name gfpgan \
--volume <absolute/path/inputs>:/app/inputs \
--volume <absolute/path/results>:/app/results \
-e BASICSR_JIT=True \
{{ DOCKERHUB_REPOSITORY }}/GFPGAN:latest \
python3 inference_gfpgan.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/cropped_faces --save_root results --arch original --channel 1 --aligned
```

#### v0.2.0

Using <https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.1/RealESRGAN_x2plus.pth>

```sh
docker run \
--name gfpgan \
--volume <absolute/path/inputs>:/app/inputs \
--volume <absolute/path/results>:/app/results \
{{ DOCKERHUB_REPOSITORY }}/GFPGAN:latest \
python3 inference_gfpgan.py --upscale 2 --test_path inputs/whole_imgs --save_root results
```

### Training

Follow training steps provided [here](#computer-training) until step 3.

```sh
nvidia-docker run \
--name gfpgan \
--volume <absolute/path/experiments/pretrained_models>:/app/experiments/pretrained_models \
--volume <absolute/path/train_gfpgan_v1.yml>:/app/train_gfpgan_v1.yml \
-e BASICSR_JIT=True \
{{ DOCKERHUB_REPOSITORY }}/GFPGAN:latest \
python3 -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 gfpgan/train.py -opt options/train_gfpgan_v1.yml --launcher pytorch
```

## :scroll: License and Acknowledgement

GFPGAN is released under Apache License Version 2.0.
Expand Down