Photo Restoration
This example demonstrates how to run the Bringing Old Photo Back to Life photo restoration project.
Setup
Run the following commands to clone the repository, download pre-trained deep-learning model data files used by the software and configure a Python virtualenv used to run the tools.
NOTE: this example uses almost 7GB of disk space.
# Create a directory we'll clone and build a few repositories.
mkdir -p photo-restoration && cd photo-restoration
# Download and audit the garden file we're going to run.
wget https://gitlab.com/garden-rs/garden/-/raw/main/doc/src/examples/photo-restoration/garden.yaml
cat garden.yaml
# One-time setup: Clone all of the trees. This will clone an "old-photos" repo.
garden grow old-photos
# One-time setup: Download resources.
garden setup old-photos
Run the Software
Now that everything is setup we can run the tools using the custom run
command
provided by the garden.yaml
file. The run.py
script takes several options.
garden run old-photos -- --help
Arguments can be passed directly to run.py
by passing additional arguments
after the special double-dash --
"end of options" marker.
The example above pases the --help
option for demonstration purposes.
You will have to specify the --input_folder <folder>
and --output_folder <folder>
in order to use the photo restoration tool. See the --help
output for more details.
garden.yaml
The following is the contents of the garden.yaml
file used in this example.
The setup
command defines what happens during garden setup old-photos
.
The run
command defines when happens during garden run old-photos
.
Additional command-line arguments specified after the double-dash --
marker are
available to commands via conventional $1
, $2
, $N
, ... "$@"
shell variables.
trees:
old-photos:
description: |
Restore old photos using machine-learning.
$ garden grow old-photos
$ garden setup old-photos
$ garden run old-photos -- --help
url: "https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life.git"
links:
- "https://colab.research.google.com/drive/1NEm6AsybIiC5TwTU_4DqDkQO0nFRB-uA?usp=sharing&authuser=2#scrollTo=32jCofdSr8AW"
- "http://raywzy.com/Old_Photo/"
- "https://news.ycombinator.com/item?id=25148253"
environment:
PATH: "${TREE_PATH}/${env3}/bin"
commands:
# "setup" uses ">" post-commands to run "setup/virtualenv" and "setup/download-*".
setup>:
- setup/virtualenv
- setup/download-face-landmarks
- setup/download-face-checkpoints
- setup/download-global-checkpoints
setup/virtualenv: |
test -d ${env3} || (
python3 -m venv ${env3}
${env3}/bin/pip install -r requirements.txt
)
setup/download-face-landmarks: |
cd ./Face_Detection
test -f shape_predictor_68_face_landmarks.dat || (
curl -L http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 \
-o shape_predictor_68_face_landmarks.dat.bz2
bzip2 -v -d shape_predictor_68_face_landmarks.dat.bz2
)
setup/download-face-checkpoints: |
cd ./Face_Enhancement
test -f checkpoints.zip ||
curl -L https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/face_checkpoints.zip \
-o checkpoints.zip
test -d checkpoints || unzip checkpoints.zip
setup/download-global-checkpoints: |
cd ./Global
test -f checkpoints.zip ||
curl -L https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/global_checkpoints.zip \
-o checkpoints.zip
test -d checkpoints || unzip checkpoints.zip
run: ${env3}/bin/python3 run.py "$@"
variables:
env3: $ python3 -c 'import sys; print("env%s%s" % sys.version_info[:2])'