旧照片修复-模糊图片变清晰-2023年度最强神器 codeformer

CodeFormer是一种基于AI技术深度学习的人脸复原模型,由南洋理工大学和商汤科技联合研究中心联合开发。该模型通过结合了VQGAN和Transformer等技术,可以通过提供模糊或马赛克图像来生成清晰的原始图像。

功能:

1、老照片修复

2、黑白照片彩色化

3、照片马赛克修复

4、低码率视频增强,增加细节

参考资料:

GitHub - sczhou/CodeFormer: [NeurIPS 2022] Towards Robust Blind Face Restoration with Codebook Lookup Transformer

按照教程,安装环境

首先安装miniconda3

新建python3.8 环境

/home/sean.xd/miniconda3/bin/conda create -n codeformer python=3.8

新建本地的venv

/home/sean.xd/miniconda3/envs/codeformer/bin/python -m venv venv

source venv/bin/activate

按照官方教程,安装requirements.txt

pip install -r requirements.txt

按照教程,安装

python basicsr/setup.py develop

但是会遇到报错,没有cython, 那就手工安装一下

pip install cython

然后再执行 python basicsr/setup.py develop, 这次就成功了

安装dlib

/home/sean.xd/miniconda3/bin/conda install -c conda-forge dlib

安装ffmpeg

/home/sean.xd/miniconda3/bin/conda install -c conda-forge ffmpeg

下载训练好的模型

python scripts/download_pretrained_models.py facelib

python scripts/download_pretrained_models.py dlib

python scripts/download_pretrained_models.py CodeFormer

测试视频增强功能

提醒缺少ffmpeg, import ffmpeg失败

pip3 install ffmpeg-python ,这样就有了

python inference_codeformer.py --bg_upsampler realesrgan --face_upsample -w 1.0 --input_path inputs/xudong.mp4

python inference_codeformer.py --bg_upsampler realesrgan --face_upsample -w 1.0 --input_path  inputs/xudong.mp4  
inference_codeformer.py:49: RuntimeWarning: Running on CPU now! Make sure your PyTorch version matches your CUDA.The unoptimized RealESRGAN is slow on CPU. If you want to disable it, please remove `--bg_upsampler` and `--face_upsample` in command.
  warnings.warn('Running on CPU now! Make sure your PyTorch version matches your CUDA.'
Face detection model: retinaface_resnet50
Background upsampling: True, Face upsampling: True
[1/276] Processing: xudong_000000
	detect 0 faces
[2/276] Processing: xudong_000001
	detect 0 faces
[3/276] Processing: xudong_000002
	detect 0 faces
[4/276] Processing: xudong_000003
	detect 0 faces
[5/276] Processing: xudong_000004
	detect 0 faces
[6/276] Processing: xudong_000005
	detect 0 faces
[7/276] Processing: xudong_000006
	detect 0 faces
[8/276] Processing: xudong_000007
	detect 0 faces
[9/276] Processing: xudong_000008
	detect 0 faces
[10/276] Processing: xudong_000009
	detect 0 faces
 

处理的很慢,最后给kill掉了。 不过过程来看,相对顺利。

占用cpu很高

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                            
 29715 sean.xd   20   0 9967.3m   1.8g 104776 R  1237  1.5 116:27.63 python inference_codeformer.py --bg_upsampler realesrgan --face_upsample -w 1.0 --input_path inputs/xudong.mp4 

测试图片增强功能

项目有个目录,专门用于测试的。例如这张

https://github.com/sczhou/CodeFormer/blob/master/inputs/whole_imgs/03.jpg

运行如下命令

$ python inference_codeformer.py -w 0.7 --bg_upsampler realesrgan  --face_upsample  --input_path inputs/whole_imgs/03.jpg
inference_codeformer.py:49: RuntimeWarning: Running on CPU now! Make sure your PyTorch version matches your CUDA.The unoptimized RealESRGAN is slow on CPU. If you want to disable it, please remove `--bg_upsampler` and `--face_upsample` in command.
  warnings.warn('Running on CPU now! Make sure your PyTorch version matches your CUDA.'
Face detection model: retinaface_resnet50
Background upsampling: True, Face upsampling: True
[1/1] Processing: 03.jpg
    detect 1 faces

All results are saved in results/test_img_0.7

 

不得不说,效果是真的牛批!

使用time命令,看看执行总共耗时多少。32核CPU,耗时55秒。如果是单核心cpu,则大概耗时8min多。

real 0m55.259s

user 8m35.757s

sys 1m43.415s

再多测试几张照片

  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Retouch Pilot v3.10.2是一款非常完美的相片修复工具,能够快速的将一系列老照片来进行修复,是一款非常实用的照片翻新修复工具,通过它可以对一些损坏的照片进行修复,可以修复片中的污点刮痕等细小的瑕疵,除此之外还可以将它当做水印去除工具来使用,可以完美地清除图片中的LOGO水印等,即使在复杂的背景下也可以完成。可真是老照片的救星啊! 以前我们修复的老照片都是使用PS,对技术要求比较高,怎么办呢?后来出现了一款专门修复照片的工具Retouch Pilot,使用简单。 在胶片摄影时代(俗称“传统摄影”时代),修复一张严重破损的照片,步骤非常复杂:首先把照片翻拍放大成低反差照片,之后用铅笔、毛笔和刀片进行修 整,之后再翻拍放大出照片;在新翻拍的照片上修整,再根据照片破损的程度和修复的效果决定翻拍和修整的次数,直到修好、翻拍放大出成品照片为止。 如今,有了电子计算机这个高效的工具,图像可以转为数字文件进行后期数字化处理,照片修复得容易和简单了。不过,这是单纯从技术方面,或者说是修整工具方面来说的。如果不懂得修像的原理和方法,用再高级的电子计算机也是不行的,照片修复都不会得容易和简单。 使用方法可以看软件界面提供的DEMO。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值