旧照片修复
- 旧照片修复 推荐度:
- 相关推荐
旧照片修复
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_000000detect 0 faces
[2/276] Processing: xudong_000001detect 0 faces
[3/276] Processing: xudong_000002detect 0 faces
[4/276] Processing: xudong_000003detect 0 faces
[5/276] Processing: xudong_000004detect 0 faces
[6/276] Processing: xudong_000005detect 0 faces
[7/276] Processing: xudong_000006detect 0 faces
[8/276] Processing: xudong_000007detect 0 faces
[9/276] Processing: xudong_000008detect 0 faces
[10/276] Processing: xudong_000009detect 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
测试图片增强功能
项目有个目录,专门用于测试的。例如这张
.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 facesAll results are saved in results/test_img_0.7
不得不说,效果是真的牛批!
使用time命令,看看执行总共耗时多少。32核CPU,耗时55秒。如果是单核心cpu,则大概耗时8min多。
real 0m55.259s
user 8m35.757s
sys 1m43.415s
再多测试几张照片
- 南宁市计算机技术专业学校,南宁电脑技术学校有哪些
- 卷积与反卷积(转置卷积)关系的公式推导 及其各自的形式
- android studio 打包cocos creator项目
- java tooltip
- linux 下dump的使用
- Android gridview keep item selected
- LRUCache算法
- 职场交流
- Revit 二次开发前景
- Blender 3D Architecture, Buildings, and Scenery
- 电话银行
- ext2与ext3的区别
- C++实现多线程及其三种方法实现多线程同步
- JAVA常见类(十二)Calendar类
- 【TCP专题】TCP连接断开
- Python用try
- 渗透常用SQL注入语句大全