当前位置: 首页 > news >正文

Python开源项目GPEN——人脸重建(Face Restoration),模糊清晰、划痕修复及黑白上色的实践

无论是自己、家人或是朋友、客户的照片,免不了有些是黑白的、被污损的、模糊的,总想着修复一下。作为一个程序员 或者 程序员的家属,当然都有责任满足他们的需求、实现他们的想法。除了这个,学习了本文的成果,或许你还可以用来赚点小钱。

Windows下Python及Anaconda的安装与设置、代码执行之保姆指南icon-default.png?t=N7T8https://blog.csdn.net/beijinghorn/article/details/134347642

8 GPEN

8.1 论文Paper


GAN Prior Embedded Network for Blind Face Restoration in the Wild

Paper: https://arxiv.org/abs/2105.06070
Supplementary: https://www4.comp.polyu.edu.hk/~cslzhang/paper/GPEN-cvpr21-supp.pdf
Demo: https://vision.aliyun.com/experience/detail?spm=a211p3.14020179.J_7524944390.17.66cd4850wVDkUQ&tagName=facebody&children=EnhanceFace
ModelScope: https://www.modelscope.cn/models/damo/cv_gpen_image-portrait-enhancement/summary

作者:
Tao Yang, Peiran Ren, Xuansong Xie, https://cg.cs.tsinghua.edu.cn/people/~tyang
Lei Zhang https://www4.comp.polyu.edu.hk/~cslzhang

DAMO Academy, Alibaba Group, Hangzhou, China
Department of Computing, The Hong Kong Polytechnic University, Hong Kong, China

8.2 功能

8.2.1 旧照修复Face Restoration
   

8.2.2 纹理重建Selfie Restoration

8.2.3 人脸重建Face Colorization

8.2.4 划痕修复Face Inpainting

8.2.5 Conditional Image Synthesis (Seg2Face)

8.3 News

(2023-02-15) GPEN-BFR-1024 and GPEN-BFR-2048 are now publicly available. Please download them via [ModelScope2].
(2023-02-15) We provide online demos via [ModelScope1] and [ModelScope2].
(2022-05-16) Add x1 sr model. Add --tile_size to avoid OOM.
(2022-03-15) Add x4 sr model. Try --sr_scale.
(2022-03-09) Add GPEN-BFR-2048 for selfies. I have to take it down due to commercial issues. Sorry about that.
(2021-12-29) Add online demos  Hugging Face Spaces. Many thanks to CJWBW and AK391.
(2021-12-16) Release a simplified training code of GPEN. It differs from our implementation in the paper, but could achieve comparable performance. We strongly recommend to change the degradation model.
(2021-12-09) Add face parsing to better paste restored faces back.
(2021-12-09) GPEN can run on CPU now by simply discarding --use_cuda.
(2021-12-01) GPEN can now work on a Windows machine without compiling cuda codes. Please check it out. Thanks to Animadversio. Alternatively, you can try GPEN-Windows. Many thanks to Cioscos.
(2021-10-22) GPEN can now work with SR methods. A SR model trained by myself is provided. Replace it with your own model if necessary.
(2021-10-11) The Colab demo for GPEN is available now google colab logo.

8.4 下载模型 Download models from Modelscope


Install modelscope:
https://www.modelscope.cn/models/damo/cv_gpen_image-portrait-enhancement-hires/summary
https://www.modelscope.cn/models/damo/cv_gpen_image-portrait-enhancement/summary
https://www.modelscope.cn/models/damo/cv_gpen_image-portrait-enhancement-hires/summary

pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
Run the following codes:

import cv2
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.outputs import OutputKeys

portrait_enhancement = pipeline(Tasks.image_portrait_enhancement, model='damo/cv_gpen_image-portrait-enhancement-hires')
result = portrait_enhancement('https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/marilyn_monroe_4.jpg')
cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])
It will automatically download the GPEN models. You can find the model in the local path ~/.cache/modelscope/hub/damo. Please note pytorch_model.pt, pytorch_model-2048.pt are respectively the 1024 and 2048 versions.

8.5 依赖项Usage


python: https://img.shields.io/badge/python-v3.7.4-green.svg?style=plastic
pytorch: https://img.shields.io/badge/pytorch-v1.7.0-green.svg?style=plastic
cuda: https://img.shields.io/badge/cuda-v10.2.89-green.svg?style=plastic
driver: https://img.shields.io/badge/driver-v460.73.01-green.svg?style=plastic
gcc: https://img.shields.io/badge/gcc-v7.5.0-green.svg?style=plastic

8.5.1 Clone this repository:

git clone https://github.com/yangxy/GPEN.git
cd GPEN

8.5.2 Download RetinaFace model and our pre-trained model (not our best model due to commercial issues) and put them into weights/.

RetinaFace-R50 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/RetinaFace-R50.pth
ParseNet-latest https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/ParseNet-latest.pth
model_ir_se50 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/model_ir_se50.pth
GPEN-BFR-512 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-BFR-512.pth
GPEN-BFR-512-D https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-BFR-512-D.pth
GPEN-BFR-256 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-BFR-256.pth
GPEN-BFR-256-D https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-BFR-256-D.pth
GPEN-Colorization-1024 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-Colorization-1024.pth
GPEN-Inpainting-1024 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-Inpainting-1024.pth
GPEN-Seg2face-512 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/GPEN-Seg2face-512.pth
realesrnet_x1 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/realesrnet_x1.pth
realesrnet_x2 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/realesrnet_x2.pth
realesrnet_x4 https://public-vigen-video.oss-cn-shanghai.aliyuncs.com/robin/models/realesrnet_x4.pth


8.5.3 Restore face images:

python demo.py --task FaceEnhancement --model GPEN-BFR-512 --in_size 512 --channel_multiplier 2 --narrow 1 --use_sr --sr_scale 4 --use_cuda --save_face --indir examples/imgs --outdir examples/outs-bfr
Colorize faces:
python demo.py --task FaceColorization --model GPEN-Colorization-1024 --in_size 1024 --use_cuda --indir examples/grays --outdir examples/outs-colorization
Complete faces:
python demo.py --task FaceInpainting --model GPEN-Inpainting-1024 --in_size 1024 --use_cuda --indir examples/ffhq-10 --outdir examples/outs-inpainting
Synthesize faces:
python demo.py --task Segmentation2Face --model GPEN-Seg2face-512 --in_size 512 --use_cuda --indir examples/segs --outdir examples/outs-seg2face
Train GPEN for BFR with 4 GPUs:
CUDA_VISIBLE_DEVICES='0,1,2,3' python -m torch.distributed.launch --nproc_per_node=4 --master_port=4321 train_simple.py --size 1024 --channel_multiplier 2 --narrow 1 --ckpt weights --sample results --batch 2 --path your_path_of_croped+aligned_hq_faces (e.g., FFHQ)
When testing your own model, set --key g_ema.

Please check out run.sh for more details.

8.6 Main idea

8.7 Citation

If our work is useful for your research, please consider citing:

@inproceedings{Yang2021GPEN,
    title={GAN Prior Embedded Network for Blind Face Restoration in the Wild},
    author={Tao Yang, Peiran Ren, Xuansong Xie, and Lei Zhang},
    booktitle={IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
    year={2021}
}

8.8 License

© Alibaba, 2021. For academic and non-commercial use only.

8.9 Acknowledgments

We borrow some codes from Pytorch_Retinaface, stylegan2-pytorch, Real-ESRGAN, and GFPGAN.

8.10 Contact

If you have any questions or suggestions about this paper, feel free to reach me at yangtao9009@gmail.com.
 

相关文章:

  • 基于蝠鲼觅食算法优化概率神经网络PNN的分类预测 - 附代码
  • 简单的 UDP 网络程序
  • Flink CDC
  • Android R.fraction
  • 快速使用vscode写python
  • element-plus使用el-date-picker组件时,如何禁止用户选择当前时间之后的日时分秒
  • 有什么进销存软件,比较适合零售行业日常开单要求及库存记录?
  • 设计模式-状态模式-笔记
  • Unable to find a single main class from the following candidates
  • leetcode栈和队列三剑客
  • 设计模式-备忘录模式-笔记
  • requests库进行爬虫ip请求时遇到的错误解决方法
  • 网申线上测评,要不要找人代做在线测评?
  • Feature Pyramid Networks for Object Detection(2017.4)
  • 校招社招hr黑话
  • -------------------- 第二讲-------- 第一节------在此给出链表的基本操作
  • 【附node操作实例】redis简明入门系列—字符串类型
  • Java 23种设计模式 之单例模式 7种实现方式
  • JavaScript服务器推送技术之 WebSocket
  • October CMS - 快速入门 9 Images And Galleries
  • socket.io+express实现聊天室的思考(三)
  • spring boot下thymeleaf全局静态变量配置
  • 机器学习学习笔记一
  • 面试遇到的一些题
  • 如何合理的规划jvm性能调优
  • 我建了一个叫Hello World的项目
  •  一套莫尔斯电报听写、翻译系统
  • 这几个编码小技巧将令你 PHP 代码更加简洁
  • 智能情侣枕Pillow Talk,倾听彼此的心跳
  • $.each()与$(selector).each()
  • (145)光线追踪距离场柔和阴影
  • (LeetCode 49)Anagrams
  • (独孤九剑)--文件系统
  • (七)c52学习之旅-中断
  • (三)终结任务
  • (四)汇编语言——简单程序
  • (一)python发送HTTP 请求的两种方式(get和post )
  • (原創) 如何優化ThinkPad X61開機速度? (NB) (ThinkPad) (X61) (OS) (Windows)
  • (转)淘淘商城系列——使用Spring来管理Redis单机版和集群版
  • ***微信公众号支付+微信H5支付+微信扫码支付+小程序支付+APP微信支付解决方案总结...
  • .htaccess配置常用技巧
  • .mysql secret在哪_MySQL如何使用索引
  • .NET 发展历程
  • .NET 同步与异步 之 原子操作和自旋锁(Interlocked、SpinLock)(九)
  • .NET8.0 AOT 经验分享 FreeSql/FreeRedis/FreeScheduler 均已通过测试
  • .NET开源项目介绍及资源推荐:数据持久层 (微软MVP写作)
  • .NET下ASPX编程的几个小问题
  • .Net小白的大学四年,内含面经
  • @JsonFormat与@DateTimeFormat注解的使用
  • @PreAuthorize注解
  • [100天算法】-每个元音包含偶数次的最长子字符串(day 53)
  • [2015][note]基于薄向列液晶层的可调谐THz fishnet超材料快速开关——
  • [ARC066F]Contest with Drinks Hard
  • [Assignment] C++1
  • [C++]18:set和map的使用