# 克隆项目到工作目录
git clone https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life.git
# clone 此项目,将里面的sync_batchnorm文件夹复制到项目的Global/detection_models和Face_Enhancement/models/networks/文件夹中
git clone https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
# 下载权重文件,这里不建议自己训练,耗时不说还不一定有官方给的好
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 ../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 ../Global/
wget https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/global_checkpoints.zip
unzip global_checkpoints.zip
# 安装依赖
cd ../
pip install -r requirements.txt
# 直接将照片放到test_iamges中,GPU 0/-1 0:使用GPU,-1:不使用GPU,--with_scratch照片有折痕
python run.py --GPU 0
# 在ouput文件夹中就可以看到修复好的文件了,也可以像官方那样指定输入文件夹和输出文件夹
# 克隆项目到工作目录
git clone https://github.com/jantic/DeOldify.git
# 安装依赖
pip install -r requirements.txt
# 创建models文件夹并下载权重文件
mkdir DeOldify/models
cd DeOldify/models
wget https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth
wget https://www.dropbox.com/s/usf7uifrctqw9rl/ColorizeStable_gen.pth
wget https://data.deepai.org/deoldify/ColorizeVideo_gen.pth
run.py
,编写可参考项目中的.ipynb文件from deoldify import device
from deoldify.device_id import DeviceId
#choices: CPU, GPU0...GPU7
device.set(device=DeviceId.GPU0)
from deoldify.visualize import *
plt.style.use('dark_background')
torch.backends.cudnn.benchmark=True
import warnings
warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")
#true:为artistic模式,false:为stable模式
colorizer = get_image_colorizer(artistic=True)
# 可以修改
render_factor=35
# 输出文件
source_path = 'input_images/2_s.jpg'
result_path = None
colorizer.plot_transformed_image(path=source_path, render_factor=render_factor, compare=True)
python run.py
如果同时需要照片修复以及上色,建议先上色再进行修复操作。
照片记录故事,用心描绘生活!