老照片修复Bringing Old Photos Back to Life实践

发布于:2023-02-14 ⋅ 阅读:(675) ⋅ 点赞:(0)

github地址  https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life
下载源码

git clone https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life.git

下载组件

cd Face_Enhancement/models/networks/
git clone https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .
cd ../../../
cd Global/detection_models
git clone https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .
cd ../../

下载训练模型

cd Face_Detection/
wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
bzip2 -d shape_predictor_68_face_landmarks.dat.bz2
cd ../
cd Face_Enhancement/
wget https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/face_checkpoints.zip
unzip face_checkpoints.zip
cd ../
cd Global/
wget https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/global_checkpoints.zip
unzip global_checkpoints.zip
cd ../

资料包

1.shape_predictor_68_face_landmarks.dat.bz2

链接:https://pan.baidu.com/s/1Aa5KnBATUIusuKJ4SBiS8w 
提取码:6nwl

2.face_checkpoints.zip

链接:https://pan.baidu.com/s/13CU_pj1n8D17uN7BsDG0GA 
提取码:b7j1

3.global_checkpoints.zip

链接:https://pan.baidu.com/s/1xub_9z3jyqMEZNqZwg7LEA 
提取码:505v

4.python-3.7.4-amd64.exe

链接:https://pan.baidu.com/s/1bq2skp0GtUo4WAeIPrCJvw 
提取码:5yt7

安装依赖

pip install -r requirements.txt

修改代码

run.py,加入一行代码:

os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"

.\global\detection_models\networks.py,修改:

from .sync_batchnorm.replicate import DataParallelWithCallback
from .antialiasing import Downsample

.\Face_Enhancement\models\networks\normalization.py,修改:

from .sync_batchnorm import SynchronizedBatchNorm2d

将待修复的带划痕/有破损的老照片放到:.\test_images\old_w_scratch 目录下,将不带划痕需要改进色彩或清晰度的老照片放到:.\test_images\old 目录下,运行以下命令行

python run.py --input_folder D:\\learn_project\\Bringing-Old-Photos-Back-to-Life\\test_images\\old_w_scratch --output_folder D:\\learn_project\\Bringing-Old-Photos-Back-to-Life\\output --GPU -1  --with_scratch
python run.py --input_folder D:\\learn_project\\Bringing-Old-Photos-Back-to-Life\\test_images\\old --output_folder D:\\learn_project\\Bringing-Old-Photos-Back-to-Life\\output --GPU -1

注意

1. GPU can be set 0 or 0,1,2 or 0,2; use -1 for CPU

使用GPU需要下载GPU版本的torch

下载链接https://pytorch.org/get-started/previous-versions/

查看NVIDIA支持的CUDA版本

NVIDIA控制面板 --> 帮助 --> 系统信息 --> 组件

2. CUDA out of memory

主要问题是内存不够. 

对于处理没有裂痕的图片的操作,我们可以将Global \ test.py中的data_transforms函数中的

h = int(round(oh / 4)*4)
w = int(round(ow / 4)*4)

 直接修改为我们想要输入的图片缩放成能处理的像素大小,比如我这里就修改为

w = 450
h = 450

对于处理有裂痕的图片,我们可以将Global \ detection.py中ata_transforms函数中if full_size == "full_size"中的

h = int(round(oh / 16) * 16)
w = int(round(ow / 16) * 16)

改为

h = 256
w = 256

3.c++环境

Visual Studio下载地址https://visualstudio.microsoft.com/zh-hans/vs/

4.安装dlib库

pip install cmake
pip install dlib

本文含有隐藏内容,请 开通VIP 后查看