Python开源项目RestoreFormer(++)——人脸重建(Face Restoration),模糊清晰、划痕修复及黑白上色的实践
有关 Python 和 Anaconda 及 RestoreFormer 运行环境的安装与设置请参阅:
Python开源项目CodeFormer——人脸重建(Face Restoration),模糊清晰、划痕修复及黑白上色的实践
https://blog.csdn.net/beijinghorn/article/details/134334021
本文介绍两个开源项目 RestoreFormer 及其后续 RestoreFormer++。
1 RESTOREFORMER
https://github.com/wzhouxiff/RestoreFormer
1.1 进化史Updating
- 20230915 Update an online demo Huggingface Gradio
- 20230915 A more user-friendly and comprehensive inference method refer to our RestoreFormer++
- 20230116 For convenience, we further upload the test datasets, including CelebA (both HQ and LQ data), LFW-Test, CelebChild-Test, and Webphoto-Test, to OneDrive and BaiduYun.
- 20221003 We provide the link of the test datasets.
- 20220924 We add the code for metrics in scripts/metrics.
1.2 论文RestoreFormer
This repo includes the source code of the paper: "RestoreFormer: High-Quality Blind Face Restoration from Undegraded Key-Value Pairs" (CVPR 2022) by Zhouxia Wang, Jiawei Zhang, Runjian Chen, Wenping Wang, and Ping Luo.

RestoreFormer tends to explore fully-spatial attentions to model contextual information and surpasses existing works that use local operators. It has several benefits compared to prior arts. First, it incorporates a multi-head coross-attention layer to learn fully-spatial interations between corrupted queries and high-quality key-value pairs. Second, the key-value pairs in RestoreFormer are sampled from a reconstruction-oriented high-quality dictionary, whose elements are rich in high-quality facial features specifically aimed for face reconstruction.
1.3 运行环境Environment
python>=3.7
pytorch>=1.7.1
pytorch-lightning==1.0.8
omegaconf==2.0.0
basicsr==1.3.3.4
Warning Different versions of pytorch-lightning and omegaconf may lead to errors or different results.
1.4 数据集与模型Preparations of dataset and models
1.4.1 Dataset:
Training data: Both HQ Dictionary and RestoreFormer in our work are trained with FFHQ which attained from FFHQ repository. The original size of the images in FFHQ are 1024x1024. We resize them to 512x512 with bilinear interpolation in our work. Link this dataset to ./data/FFHQ/image512x512.
https://pan.baidu.com/s/1SjBfinSL1F-bbOpXiD0nlw?pwd=nren
1.4.2 测试数据Test data:
CelebA-Test-HQ: OneDrive; BaiduYun(code mp9t)
https://pan.baidu.com/s/1tMpxz8lIW50U8h00047GIw?pwd=mp9t
CelebA-Test-LQ: OneDrive; BaiduYun(code 7s6h)
https://pan.baidu.com/s/1y6ZcQPCLyggj9VB5MgoWyg?pwd=7s6h
LFW-Test: OneDrive; BaiduYun(code 7fhr). Note that it was align with dlib.
https://pan.baidu.com/s/1UkfYLTViL8XVdZ-Ej-2G9g?pwd=7fhr
CelebChild: OneDrive; BaiduYun(code rq65)
https://pan.baidu.com/s/1pGCD4TkhtDsmp8emZd8smA?pwd=rq65
WepPhoto-Test: OneDrive; BaiduYun(code nren)
https://pan.baidu.com/s/1SjBfinSL1F-bbOpXiD0nlw?pwd=nren
Model: Both pretrained models used for training and the trained model of our RestoreFormer can be attained from OneDrive or BaiduYun(code x6nn). Link these models to ./experiments.
https://pan.baidu.com/s/1EO7_1dYyCuORpPNosQgogg?pwd=x6nn
1.5 测试Test
sh scripts/test.sh
1.6 自训练Training
sh scripts/run.sh
Note.
The first stage is to attain HQ Dictionary by setting conf_name in scripts/run.sh to 'HQ_Dictionary'.
The second stage is blind face restoration. You need to add your trained HQ_Dictionary model to ckpt_path in config/RestoreFormer.yaml and set conf_name in scripts/run.sh to 'RestoreFormer'.
Our model is trained with 4 V100 GPUs.
1.7 度量 Metrics
sh scripts/metrics/run.sh
Note.
You need to add the path of CelebA-Test dataset in the script if you want get IDD, PSRN, SSIM, LIPIS.
1.8 引用 Citation
@article{wang2022restoreformer,
title={RestoreFormer: High-Quality Blind Face Restoration from Undegraded Key-Value Pairs},
author={Wang, Zhouxia and Zhang, Jiawei and Chen, Runjian and Wang, Wenping and Luo, Ping},
booktitle={The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
year={2022}
}
1.9 知识 Acknowledgement
We thank everyone who makes their code and models available, especially Taming Transformer, basicsr, and GFPGAN.
1.10 联系 Contact
For any question, feel free to email wzhoux@connect.hku.hk or zhouzi1212@gmail.com.
2 RESTOREFORMER++
https://github.com/wzhouxiff/RestoreFormerPlusPlus
2.1 进化史ToDo List
20230915 Update an online demo Huggingface Gradio
20230915 Provide a user-friendly method for inference.
It is avaliable for background SR with RealESRGAN.
basicsr should be upgraded to 1.4.2.
20230914 Upload model
20230914 Realse Code
20221120 Introducing the project.
2.2 论文RestoreFormer++
This repo is a official implementation of "RestoreFormer++: Towards Real-World Blind Face Restoration from Undegraded Key-Value Paris".
https://arxiv.org/pdf/2308.07228.pdf
RestoreFormer++ is an extension of our RestoreFormer. It proposes to restore a degraded face image with both fidelity and realness by using the powerful fully-spacial attention mechanisms to model the abundant contextual information in the face and its interplay with our reconstruction-oriented high-quality priors. Besides, it introduces an extending degrading model (EDM) that contains more realistic degraded scenarios for training data synthesizing, which helps to enhance its robustness and generalization towards real-world scenarios. Our results compared with the state-of-the-art methods and performance with/without EDM are in following:
RestoreFormer++是RestoreFormer的扩展。它提出了利用强大的全空间注意机制来模拟人脸中丰富的上下文信息及其与我们面向重构的高质量先验的相互作用,以保真度和真实度恢复退化的人脸图像。此外,它还引入了一个扩展的退化模型(EDM),该模型包含更真实的退化场景,用于训练数据合成,这有助于增强其鲁棒性和对真实场景的泛化。我们的结果与最先进的方法和性能有/没有EDM的比较如下:

2.3 运行环境Environment
python>=3.7
pytorch>=1.7.1
pytorch-lightning==1.0.8
omegaconf==2.0.0
basicsr==1.3.3.4 basicsr>=1.4.2
realesrgan==0.3.0
Warning Different versions of pytorch-lightning and omegaconf may lead to errors or different results.
警告:不同版本的pytorch-lightning和omegaconf可能导致错误或不同的结果。
2.4 数据集与模型Preparations of dataset and models
Dataset:
Training data: Both ROHQD and RestoreFormer++ in our work are trained with FFHQ which attained from FFHQ repository. The original size of the images in FFHQ are 1024x1024. We resize them to 512x512 with bilinear interpolation in our work. Link this dataset to ./data/FFHQ/image512x512.
https://github.com/NVlabs/ffhq-dataset
Test data: CelebA-Test, LFW-Test, WebPhoto-Test, and CelebChild-Test
https://pan.baidu.com/s/1iUvBBFMkjgPcWrhZlZY2og?pwd=test
http://vis-www.cs.umass.edu/lfw/#views
https://xinntao.github.io/projects/gfpgan
训练数据:在我们的工作中,ROHQD和RestoreFormer++都是用FFHQ库获得的FFHQ训练的。FFHQ中的图像的原始大小是1024x1024。在我们的工作中,我们用双线性插值将它们调整为512x512。将此数据集链接到./data/FFHQ/image512x512。
Model: Both pretrained models used for training and the trained model of our RestoreFormer and RestoreFormer++ can be attained from Google Driver. Link these models to ./experiments.
https://connecthkuhk-my.sharepoint.com/:f:/g/personal/wzhoux_connect_hku_hk/EkZhGsLBtONKsLlWRmf6g7AB_VOA_6XAKmYUXLGKuNBsHQ?e=ic2LPl
模型:用于训练的预训练模型和我们的RestoreFormer和RestoreFormer++的训练模型都可以从谷歌盘中获得。将这些模型链接(存放)到:/experiments 文件夹。
2.5 快速指南Quick Inference
python inference.py -i data/aligned -o results/RF++/aligned -v RestoreFormer++ -s 2 --aligned --save
python inference.py -i data/raw -o results/RF++/raw -v RestoreFormer++ -s 2 --save
python inference.py -i data/aligned -o results/RF/aligned -v RestoreFormer -s 2 --aligned --save
python inference.py -i data/raw -o results/RF/raw -v RestoreFormer -s 2 --save
Note: Related codes are borrowed from GFPGAN.
https://github.com/TencentARC/GFPGAN
2.6 测试Test
sh scripts/test.sh
scripts/test.sh
exp_name='RestoreFormer'
exp_name='RestoreFormerPlusPlus'
root_path='experiments'
out_root_path='results'
align_test_path='data/aligned'
# unalign_test_path='data/raw'
tag='test'
outdir=$out_root_path'/'$exp_name'_'$tag
if [ ! -d $outdir ];then
mkdir -m 777 $outdir
fi
CUDA_VISIBLE_DEVICES=0 python -u scripts/test.py \
--outdir $outdir \
-r $root_path'/'$exp_name'/last.ckpt' \
-c 'configs/'$exp_name'.yaml' \
--test_path $align_test_path \
--aligned
This codebase is available for both RestoreFormer and RestoreFormerPlusPlus. Determinate the specific model with exp_name.
这个代码库可用于RestoreFormer和RestoreFormer++。使用exp_name确定特定的模型。
Setting the model path with root_path
使用root_path设置模型路径
Restored results are save in out_root_path
恢复的结果将保存在out_root_path中
Put the degraded face images in test_path
将退化的人脸图像放入test_path中
If the degraded face images are aligned, set --aligned, else remove it from the script. The provided test images in data/aligned are aligned, while images in data/raw are unaligned and contain several faces.
如果退化的人脸图像对齐,设置对齐,否则将其从脚本中删除。所提供的数据/对齐中的测试图像是对齐的,而数据/原始中的图像是未对齐的,并且包含多个面。
2.7 自我训练Training
sh scripts/run.sh
scripts/run.sh
export BASICSR_JIT=True
# For RestoreFormer
# conf_name='HQ_Dictionary'
# conf_name='RestoreFormer'
# For RestoreFormer++
conf_name='ROHQD'
conf_name='RestoreFormerPlusPlus'
# gpus='0,1,2,3,4,5,6,7'
# node_n=1
# ntasks_per_node=8
root_path='PATH_TO_CHECKPOINTS'
gpus='0,'
node_n=1
ntasks_per_node=1
gpu_n=$(expr $node_n \* $ntasks_per_node)
python -u main.py \
--root-path $root_path \
--base 'configs/'$conf_name'.yaml' \
-t True \
--postfix $conf_name'_gpus'$gpu_n \
--gpus $gpus \
--num-nodes $node_n \
--random-seed True \
This codebase is available for both RestoreFormer and RestoreFormerPlusPlus. Determinate the training model with conf_name. 'HQ_Dictionary' and 'RestoreFormer' are for RestoreFormer, while 'ROHQD' and 'RestoreFormerPlusPlus' are for RestoreFormerPlusPlus.
While training 'RestoreFormer' or 'RestoreFormerPlusPlus', 'ckpt_path' in the corresponding configure files in configs/ sholud be updated with the path of the trained model of 'HQ_Dictionary' or 'ROHQD'.
这个代码库可用于RestoreFormer和RestoreFormer++。用conf_name确定训练模型。“HQ_Dictionary”和“RestoreFormer”用于RestoreFormer,而“ROHQD”和“RestoreFormer”用于RestoreFormer。
在训练“RestoreFormer”或“RestoreFormer++”时,配置中相应配置文件中的“ckpt_path”将更新训练模型的“HQ_Dictionary”或“ROHQD”的路径。
2.8 指标Metrics
sh scripts/metrics/run.sh
Note.
You need to add the path of CelebA-Test dataset in the script if you want get IDD, PSRN, SSIM, LIPIS.
Related metric models are in ./experiments/pretrained_models/
如果您想获得IDD,PSRN,SSIM,LIPIS,您需要在脚本中添加CelebA-测试数据集的路径。
相关的度量模型在。/experiments/pretrained_models/
2.9 引用Citation
@article{wang2023restoreformer++,
title={RestoreFormer++: Towards Real-World Blind Face Restoration from Undegraded Key-Value Paris},
author={Wang, Zhouxia and Zhang, Jiawei and Chen, Tianshui and Wang, Wenping and Luo, Ping},
booktitle={IEEE Transactions on Pattern Analysis and Machine Intelligence (T-PAMI)},
year={2023}
}
@article{wang2022restoreformer,
title={RestoreFormer: High-Quality Blind Face Restoration from Undegraded Key-Value Pairs},
author={Wang, Zhouxia and Zhang, Jiawei and Chen, Runjian and Wang, Wenping and Luo, Ping},
booktitle={The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
year={2022}
}
2.10 联系Contact
For any question, feel free to email wzhoux@connect.hku.hk or zhouzi1212@gmail.com.
如有任何问题,请随时发邮件至wzhoux@connect.hku.hk或zhouzi1212@gmail.com。
这两个代码都写的不好,效率低,效果差,有点应付论文的意思。
相关文章:
Python开源项目RestoreFormer(++)——人脸重建(Face Restoration),模糊清晰、划痕修复及黑白上色的实践
有关 Python 和 Anaconda 及 RestoreFormer 运行环境的安装与设置请参阅: Python开源项目CodeFormer——人脸重建(Face Restoration),模糊清晰、划痕修复及黑白上色的实践https://blog.csdn.net/beijinghorn/article/details/134…...
设计模式 -- 命令模式(Command Pattern)
命令模式:一种数据驱动的设计模式也属于行为型模式,请求以命令的形式包裹在对象中,并传给调用对象。调用对象寻找可以处理该命令的合适的对象,并把该命令传给相应的对象,该对象执行命令。你认为是命令的地方都可以使用…...
【数据分享】2021-2023年我国主要城市逐月轨道交通运营数据
以地铁为代表的轨道交通是大城市居民的主要交通出行方式之一,轨道交通的建设和运营情况也是一个城市发展水平的重要体现。本次我们为大家带来的是2021-2023年我国主要城市的逐月的轨道交通运营数据! 数据指标包括:运营线路条数(条…...
大数据-之LibrA数据库系统告警处理(ALM-12034 周期备份任务失败)
告警解释 周期备份任务执行失败,则上报该告警,如果下次备份执行成功,则恢复告警。 告警属性 告警ID 告警级别 可自动清除 12034 严重 是 告警参数 参数名称 参数含义 ServiceName 产生告警的服务名称。 RoleName 产生告警的角色…...
tx-前端笔试题记录
目录 目录 1.你最熟悉的前端框架是什么说说你对它的理解。 2.请简单实现一下js对象深度拷贝。 3.CSS 有几种方法实现垂直水平居中?请简要写一下。 4.这段程序执行之后控制台会打印什么内容? 5.下列程序的输出结果是多少?为什么? 6.有ABCDE 五个火车站,单向…...
详解Redis持久化(上篇——RDB持久化)
Redis持久化的作用和意义 Redis 持久化是一种机制,用于将内存中的数据写入磁盘,以保证数据在服务器重启时不会丢失。持久化是为了解决内存数据库(如 Redis)在服务器关闭后,数据丢失的问题。 Redis 持久化的主要作用和…...
爬虫常见风控
一.ip风控 单位时间内接口访问频率。 二.设备指纹风控 设备注册时候设备特征是否完整,信息主要包含硬件、网络、系统三部分。 硬件属性:设备品牌、型号、IMEI(国际移动设备识别码)、处理器、内存、分辨率、亮度、摄像头、电池、…...
华为ensp:边缘端口并启动BUDU保护
如上图前提是三个交换机都做了rstp,则在边缘的地方做 边缘端口并启动BUDU保护,也就是我用绿色圈出来的地方 边缘1 进入交换机的系统视图 interface e0/0/3 进入接口 stp edged-port enable quit 再退回系统视图 stp bpdu-protection 这样就可以了…...
分布式id生成数据库号段算法的golang实现
分布式id生成数据库号段算法的golang实现 介绍项目结构使用说明核心流程说明1. 定义id生成器结构体2. id生成器共有Monitor,GetOne, Close三个对外暴露的方法。3. 数据表结构 参与贡献 介绍 项目地址:gitee;github 本项目主要利用go语言(go1…...
【算法 | 模拟No.4】AcWing 756. 蛇形矩阵 AcWing 40. 顺时针打印矩阵
个人主页:兜里有颗棉花糖 欢迎 点赞👍 收藏✨ 留言✉ 加关注💓本文由 兜里有颗棉花糖 原创 收录于专栏【手撕算法系列专栏】【AcWing算法提高学习专栏】 🍔本专栏旨在提高自己算法能力的同时,记录一下自己的学习过程&a…...
数据——最为直接的答案
身处于这样一个数字化快速发展、竞争强烈的时代,不管是企业还是个人,大家都需要及时获取前沿动态信息,密切关注市场的变化。但是,在不计其数的企业中,到底行业top 是哪些企业引领潮流? 只有数据能告诉你最…...
php加密解密的用法(对称加密,非对称加密)
加密和摘要的区别 ***摘要:是从已知的数据中,通过摘要计算出一个值,一个数据对应一个或多个摘要的值 *** 比如:md5 和 sha1 sha256 hash 就是得到一个特定的值 ,同一个数据得到的md5 是一样的,不会改变的 比…...
优秀智慧园区案例 - 中建科技产业园(中建·光谷之星),万字长文解析先进智慧园区建设方案经验
一、项目背景 中建科技产业园(中建光谷之星),位于武汉光谷中心城、中国(湖北)自贸试验区武汉片区双核心区,光谷发展主轴高新大道北侧,建筑面积108万平米,是中建三局“中建之星”和“…...
Python基础详解教程------目录大纲
Python基础详解教程------让编程简单 目录 第一章、python基本概念规范... 5 1.1方法(Method)与函数(Function) 5 1.2类(Class)与函数(Function) 6 1.3变量(Variable)与参数(Parameter)及形参与实参... 7 1.4变量(Variable)与属性(Attribute)及property. 8 1.5对象(Objec…...
什么是高防IP?
什么是高防IP? 高防IP是针对互联网服务器在遭受大流量的DDOS攻击后导致服务不可用的情况下,推出的付费增值服务,用户可以通过配置高防IP,将攻击流量引流到高防IP,确保源站的稳定可靠。(无需转移数据&#…...
打开word文档报错,提示HRESULT 0x80004005 位置: 部分: /word/comments.xml,行: 0,列: 0
某用户遇到这样一个奇怪的问题,就是回复完word的批注后,保存文档再打开就会报错,提示很抱歉,无法打开XXX,因为内容有问题。,详细信息提示HRESULT 0x80004005 位置: 部分: /word/comments.xml,行: 0,列: 0 c…...
Allegro层叠中的Etch Factor-铜皮的腐蚀因子如何计算
Allegro层叠中的Etch Factor-铜皮的腐蚀因子如何计算 在用Allegro进行PCB设计的时候,Cross-section中需要填入对应的信息,一般填入每层的厚度即可,如下图 当PCB需要进行仿真分析的时候,Etch-Factor这个值是必须要填写的,如下图 目前看到的都是90这个值,这是一个理论值。 …...
20 个好用的一行 Java代码
今天分享给大家20个 令人惊叹的 Java一行代码,让你们的工作更轻松。一起来看看吧! 1. 获取浏览器 Cookie 的值 使用document.cookie 来获取 Cookie 的值。 2. 将 RGB 转换为十六进制 3. 复制到剪贴板 使用 navigator.clipboard.writeText 轻松将任何文本…...
Java编程--单例模式(饿汉模式/懒汉模式)/阻塞队列
前言 逆水行舟,不进则退!!! 目录 单例模式 饿汉模式: 懒汉模式: 什么是阻塞队列 什么是高内聚 低耦合 阻塞队列的实现 单例模式 单例模式(Singleton Pattern)是一种常见…...
【go-zero】go-zero 脚手架 simple-admin 第二章:通过goctls生成api整个项目
往期回顾 一、simple-admin 开篇:安装 了解 goctls 二、go-zero 脚手架 simple-admin 第一章:通过goctls生成rpc整个项目 | go-zero整合 ENT数据库orm框架 本章内容 往期回顾一、simple-admin 创建rpc项目实战1、创建git仓库1.1、创建任意git仓库1.2、克隆到本地2、创建API项…...
深入Linux内核:RDMA Verbs API的object/method/attr三层模型设计与实现解析
深入Linux内核:RDMA Verbs API的object/method/attr三层模型设计与实现解析 在当今高性能计算和分布式存储领域,远程直接内存访问(RDMA)技术因其极低的延迟和高吞吐量而备受青睐。作为RDMA技术的核心接口,Verbs API的设计哲学直接影响着整个生…...
obsidian-skills投资者管理:高效管理投资者关系的终极指南
obsidian-skills投资者管理:高效管理投资者关系的终极指南 【免费下载链接】obsidian-skills Agent skills for Obsidian. Teach your agent to use Markdown, Bases, JSON Canvas, and use the CLI. 项目地址: https://gitcode.com/GitHub_Trending/ob/obsidian-…...
终极实战指南:Godot PCK解包器深度解析与高效资源提取
终极实战指南:Godot PCK解包器深度解析与高效资源提取 【免费下载链接】godot-unpacker godot .pck unpacker 项目地址: https://gitcode.com/gh_mirrors/go/godot-unpacker 在游戏开发与逆向工程领域,Godot引擎的PCK文件格式一直是技术爱好者关注…...
保姆级教程:用Python调用DashScope灵积模型API,5分钟搞定你的第一个AI菜谱
5分钟实战:用Python调用DashScope打造智能菜谱生成器 第一次接触AI模型API调用时,很多人会被各种术语和配置步骤吓退。但事实上,借助像DashScope这样的平台,即使是编程新手也能快速实现有趣的应用。今天我们就从一个生活化场景出…...
【深度学习新浪潮】OpenClaw架构与技术关键点全解析:为什么它能成功,而前代框架纷纷折戟?
引言 在AI Agent从概念走向落地的过程中,AutoGPT、LangChain早期版本、BabyAGI等框架一度掀起热潮,但始终难以实现规模化、稳定化的实际生产落地。OpenClaw作为MIT主导开源的本地优先AI执行网关,上线后迅速成为现象级开源项目,其核…...
聚类算法效果评估实战:从轮廓系数到CH分数,手把手教你选对指标
聚类算法效果评估实战:从轮廓系数到CH分数,手把手教你选对指标 在数据科学项目中,聚类分析常常是探索性数据分析的重要环节。无论是客户分群、异常检测还是特征工程,我们都需要面对一个关键问题:如何客观评价聚类结果的…...
小说下载与数字图书馆构建:开源工具novel-downloader完全指南
小说下载与数字图书馆构建:开源工具novel-downloader完全指南 【免费下载链接】novel-downloader 一个可扩展的通用型小说下载器。 项目地址: https://gitcode.com/gh_mirrors/no/novel-downloader 在数字阅读时代,读者常面临三大困境:…...
2025.07.15【甲基化】methylKit实战指南:从Bioconductor安装到差异甲基化区域精准注释
1. methylKit:甲基化数据分析的瑞士军刀 第一次接触甲基化数据分析时,我被各种专业术语和复杂流程搞得晕头转向。直到发现了methylKit这个神器,才真正体会到什么叫"一站式解决方案"。作为R语言环境下最成熟的甲基化分析工具之一&a…...
从本体论到落地实践:制造业数字化转型的核心逻辑与工具选择
在技术领域,我们常常被那些闪耀的、可见的成果所吸引。今天,这个焦点无疑是大语言模型技术。它们的流畅对话、惊人的创造力,让我们得以一窥未来的轮廓。然而,作为在企业一线构建、部署和维护复杂系统的实践者,我们深知…...
BepInEx深度解析:构建Unity游戏插件生态系统的完整指南
BepInEx深度解析:构建Unity游戏插件生态系统的完整指南 【免费下载链接】BepInEx Unity / XNA game patcher and plugin framework 项目地址: https://gitcode.com/GitHub_Trending/be/BepInEx 在Unity游戏开发领域,BepInEx框架已成为插件和模组开…...
