diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..abae4af7 --- /dev/null +++ b/.dockerignore @@ -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 diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..737ef22a --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..99a8e2b2 --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index b6296252..3ca68bbc 100644 --- a/README.md +++ b/README.md @@ -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 + +```sh +nvidia-docker run \ + --name gfpgan \ + --volume :/app/inputs \ + --volume :/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 :/app/inputs \ + --volume :/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 + +```sh +docker run \ + --name gfpgan \ + --volume :/app/inputs \ + --volume :/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 :/app/experiments/pretrained_models \ + --volume :/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.