This article appears in: Institute for Artificial Intelligence

GAN generates adversarial networks, praised as “one of the most interesting ideas in the field of computer science in the past decade” by Yann LeCun, “father of convolutional networks”, and has become popular all over the Internet in recent years. Researchers use GAN to build interesting applications such as image variation, super-resolution, and motion migration.

This article introduces how to use PaddleGAN, a GAN kit based on Baidu PaddlePaddle framework, to repair old movies.

Let’s take a look at the repair first.

How’s that? It worked out pretty well. Now I will guide you step by step to achieve the restoration of old movies.

1. Install the PaddleGAN kit

The source code can be downloaded directly from Github.

git clone https://github.com/PaddlePaddle/PaddleGAN.git
Copy the code

It can also be packaged for download at the address at the end of this article.

Then check the native Python version and CUDA version. Note that you need to use a graphics card to run the PaddleGAN suite, otherwise it will be very slow.

CUDA python3.8 python3.7 python3.6
10.1
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda10.1-cudnn7-mkl_gcc8.2%2Fpaddlepaddle_gpu-2.0.0rc0.post101-cp38-cp3 8-linux_x86_64.whlCopy the code
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda10.1-cudnn7-mkl_gcc8.2%2Fpaddlepaddle_gpu-2.0.0rc0.post101-cp37-cp3 7m-linux_x86_64.whlCopy the code
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda10.1-cudnn7-mkl_gcc8.2%2Fpaddlepaddle_gpu-2.0.0rc0.post101-cp36-cp3 6m-linux_x86_64.whlCopy the code
10.0
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda10-cudnn7-mkl%2Fpaddlepaddle_gpu-2.0.0rc0.post100-cp38-cp38-linux_x 86_64.whlCopy the code
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda10-cudnn7-mkl%2Fpaddlepaddle_gpu-2.0.0rc0.post100-cp37-cp37m-linux_ x86_64.whlCopy the code
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda10-cudnn7-mkl%2Fpaddlepaddle_gpu-2.0.0rc0.post100-cp36-cp36m-linux_ x86_64.whlCopy the code
9.0
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda9-cudnn7-mkl%2Fpaddlepaddle_gpu-2.0.0rc0.post90-cp38-cp38-linux_x86 _64.whlCopy the code
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda9-cudnn7-mkl%2Fpaddlepaddle_gpu-2.0.0rc0.post90-cp37-cp37m-linux_x8 6_64.whlCopy the code
install
python -m pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda9-cudnn7-mkl%2Fpaddlepaddle_gpu-2.0.0rc0.post90-cp36-cp36m-linux_x8 6_64.whlCopy the code

After downloading the corresponding version of the PaddlePaddle framework, install it using the following command.

pip install https://paddle-wheel.bj.bcebos.com/2.0.0-rc0-gpu-cuda10.1-cudnn7-mkl_gcc8.2%2Fpaddlepaddle_gpu-2.0.0rc0.post101-cp37-cp3 7m-linux_x86_64.whlCopy the code

Then install the PaddleGAN kit.

cd PaddleGAN/
pip install -v -e .
Copy the code

Installing dependency packages

pip install -r requirments.txt -i https://pypi.douban.com/simple
Copy the code

2. Restore old movies

You will need to prepare a few minutes of black and white video clips of your own. If you don’t have one, you can download the examples at the end of this article. Go to the Applications directory and execute the script.

cd applications
python tools/video-enhance.py --input xiaobing1.mp4 --process_order  DeOldify  --output /home/aistudio/output_dir
Copy the code

–input Specifies the path of the input video file.

–output Specifies the path to save the output repair video.

–process_order specifies the algorithm, which will be executed sequentially.

Currently, the repair tool supports the following algorithms:

  • DAIN: Frame insertion algorithm, which inserts frames at 2 times the original frame rate.
  • DeepRemaster: Video repair, usually used when the original video is blurred
  • DeOldify: Color fix, color black and white video, such as the renderings at the beginning of this article
  • RealSR: Super resolution, can increase the resolution of video, while ensuring clarity, suitable for low resolution video
  • EDVR: Super resolution, can increase the resolution of video, while ensuring clarity, suitable for low resolution video

The above algorithms can be combined appropriately according to the actual situation. The resolution of the original video in the example is high enough that the super-resolution algorithm is not used.

After executing the code, the console prints the following:

You are using Paddle compiled with TensorRT, but TensorRT dynamic library is not found. Ignore this ifTensorRT is not needed.Model DeOldify proccess start.. W0108 18:59:55.299445 5019 Device_context. cc:338] Please NOTE: Device: 0, CUDA Capability: 70, Driver API Version Runtime API Version: 10.1 W0108 18:59:55.304046 5019 Device_context. cc:346] Device: 0, cuDNN Version: 7.6. [01/08 18:59:59] ppgan INFO: Found/home/aistudio/cache/ppgan/DeOldify_stable pdparams 1% | ▍ | 10/1806 [00:09 "29:50, 1.00 it/s]Copy the code

The program may take a long time to run. The running time of the program is affected by the length of the input video, the resolution, and the combination of algorithms used. At the end of the run, the fixed video will be generated at the –output path.

The source and the sample video download address: blog.aistudyclub.com/2021/01/08/…