CodeFormer是一种根据AI技能深度学习的人脸复原模型,由南洋理工大学和商汤科技联合研究中心联合开发。该模型经过结合了VQGAN和Transformer等技能,能够经过提供模糊或马赛克图画来生成清晰的原始图画。
功用:
1、老相片修正
2、黑白相片彩色化
3、相片马赛克修正
4、低码率视频增强,添加细节
参考资料:
github.com/sczhou/Code…
按照教程,装置环境
首先装置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
测验图片增强功用
项目有个目录,专门用于测验的。例如这张
github.com/sczhou/Code…
运行如下指令
$ 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
再多测验几张相片