背景
近期在进行图像处理相关需求的时候,需要对旧照片进行修复,并了解到了 CodeFormer 这个基于AI技术深度学习的人脸复原模型,对其进行环境配置和试用,特此记录。
步骤
- 源码下载并解压进入目录
- git clone https://github.com/sczhou/CodeFormer.git
- unzip CodeFormer-master.zip
- cd CodeFormer-master
- 环境安装(清华源有时候会慢,在安装过程中使用的阿里云的源):
- conda create -n codeformer python=3.8 -y
- conda activate codeformer
- pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
- python basicsr/setup.py develop
- conda install -c conda-forge dlib
- 模型下载后放置到指定文件夹
- weights/facelib 文件夹存放
- yolov5n-face.pth
- detection_mobilenet0.25_Final.pth
- detection_Resnet50_Final.pth
- parsing_parsenet.pth
- yolov5l-face.pth
- weights/CodeFormer 文件夹存放
- codeformer.pth
- weights/facelib 文件夹存放
- 测试模型
- 单独图片人脸修复:python inference_codeformer.py -w 0.2 --has_aligned --input_path face.jpg
- 输出: Background upsampling: False, Face upsampling: False [1/1] Processing: face.jpg All results are saved in results/test_img_0.2
- 单独图片人脸修复:python inference_codeformer.py -w 0.2 --has_aligned --input_path face.jpg
执行过程

[人脸修复]基于CodeFormer的人脸修复模型配置-修复效果
总结
基于CodeFormer,搭建环境后对人脸进行修复,并举出修复效果。
参考
- https://gitee.com/alexgaoyh
- https://pap-docs.pap.net.cn/