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

有关 Python 和 Anaconda 及 RestoreFormer 运行环境的安装与设置请参阅:

Python开源项目CodeFormer——人脸重建(Face Restoration),模糊清晰、划痕修复及黑白上色的实践icon-default.png?t=N7T8https://blog.csdn.net/beijinghorn/article/details/134334021

本文介绍两个开源项目 RestoreFormer 及其后续 RestoreFormer++。

1 RESTOREFORMER

https://github.com/wzhouxiff/RestoreFormer

1.1 进化史Updating

  1. 20230915 Update an online demo Huggingface Gradio
  2. 20230915 A more user-friendly and comprehensive inference method refer to our RestoreFormer++
  3. 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.
  4. 20221003 We provide the link of the test datasets.
  5. 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。

这两个代码都写的不好,效率低,效果差,有点应付论文的意思。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/138904.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

25期代码随想录算法训练营第十四天 | 二叉树 | 递归遍历、迭代遍历

目录 递归遍历前序遍历中序遍历后序遍历 迭代遍历前序遍历中序遍历后序遍历 递归遍历 前序遍历 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val0, leftNone, rightNone): # self.val val # self.left left # …

CSS的初步学习

CSS 层叠样式表 (Cascading Style Sheets). CSS 能够对网页中元素位置的排版进行像素级精确控制, 实现美化页面的效果. 能够做到页面的样式和结 构分离. CSS 就是 “东方四大邪术” 之化妆术 CSS 基本语法规范: 选择器 若干属性声明 选择器决定针对谁修改 (找谁) 声明决定修…

webrtc推拉流 srs报错:DTLS_HANG DTLS: > Hang, done=0, version=-1, arq=0

执行了./objs/srs -c conf/rtc.conf 打开了srs的推拉流网页: 推流 拉流 srs报错如下: [2023-11-08 21:55:23.489][Warn][44992][8xvf4d62][104][DTLS_HANG] DTLS: Hang, done0, version-1, arq0 观看srs日志,在sdp offer,answer…

MySQL中的json使用注意

MySQL中json是一种重要的数据类型 好的点在于其不必事先定义列得名称啥的 不过不要将明显的关系型数据作为json来存储,例如用户余额、姓名、身份证等,这些是用户必须包含的数据 json适合存储的是给每个用户(或者物品)打的标签&…

MySQL Command Line Client 运行闪退问题解决,缺少my.ini文件

MySQL Command Line Client 运行闪退问题解决: 问题排查: 1.找到Command Line Client的路径位置,并查看属性,步骤截图: 查看属性: 查看属性中的目标路径: 2.进入属性中的目标路径,…

最新支付宝转卡码生成之转账源代码(隐藏部分卡号)

一、需要准备好自己的卡号、名称、以及对应的姓名 二、然后将自己的信息填入下面的代码中 三、然后将拼接好的代码,利用转码技术生产对应的二维码 四、这样一个跳转银行卡二维码的转账码就做好了 效果演示:如下 支付宝扫码、跳转码、转卡码、隐藏卡号…

51单片机应用从零开始(一)

1. 单片机在哪里 单片机是一种集成电路芯片,通常被嵌入到电子设备中用于控制和处理数据,例如家电、汽车、电子玩具、智能家居等。因此,你可以在许多电子设备中找到单片机的存在。单片机通常被放置在设备的主板或控制板上。 2. 单片机是什么…

对Mysql和应用微服务做TPS压力测试

1.对Mysql 使用工具:mysqlslap工具 使用命令: mysqlslap -uroot pGG8697000!#--auto generate sql -auto generate sql-load typemixed-concurrency100,200 - number of queries1000-iterations10 - number-int-cols7 - number-charcols13auto genera…

PDF Expert for mac(专业pdf编辑器)苹果电脑

PDF Expert for Mac 是一款功能强大、界面简洁的PDF阅读、编辑和转换工具,为Mac用户提供了全面而便捷的PDF处理体验。无论是日常工作中的文档阅读、标注,还是专业需求下的编辑、转换,PDF Expert 都能满足您的各种需求。 首先,PDF…

node插件MongoDB(五)—— 库mongoose 的模块化(五)

文章目录 一、使用mongoose 模块化的原因二、准备工作2. 启动mongo.exe 和mongod.exe 两个程序连接数据库 三、基本模块的拆分1、基本逻辑2、代码3、代码图示说明 四、在index.js 中进一步的拆分1.拆分原因2.新建model文件夹存储文档的结构对象3.代码4.代码实际演示和注意点 一…

线性代数-Python-05:矩阵的逆+LU分解

文章目录 1 矩阵的逆1.1 求解矩阵的逆 2 初等矩阵2.1 初等矩阵和可逆性 3 矩阵的LU分解3.1 LU分解的实现 1 矩阵的逆 1.1 求解矩阵的逆 def inv(A):if A.row_num() ! A.col_num():return Nonen A.row_num()"""矩阵A单位矩阵"""ls LinearSyste…

SplayTree高分测试用例

测试用例结果展示 覆盖率 变异得分 测试注意点 从SplayTree测起,然后再测SubSplayTree,因为前者调用后者。SplaySubTree的remove方法大部分内容需要通过反射才能测到。value和index在SplayTree当中都不是唯一的。一个index可能对应多个value。 不足之…

Azure 机器学习 - 如何使用模板创建安全工作区

目录 先决条件了解模板配置模板连接到工作区疑难解答错误:Windows 计算机名的长度不能超过 15 个字符,并且不能全为数字或包含以下字符 本教程介绍如何使用 [Microsoft Bicep]和 [Hashicorp Terraform]模板创建以下 Azure 资源: Azure 虚拟网…

AndroidStudio gitee令牌过期 解决方式 remote:Oauth: Access token is expired

记一次,gitee令牌过期 解决方式 Oauth: Access token is expired fatal: unable to access ‘https://gitee.com/xxxx.git/’: The requested URL returned error: 403 remote: [session-e14669a3] Oauth: Access token is expired fatal: unable to access https…

网页分析和xml.etree库

源代码: Lib/xml/etree/ElementTree.py 该xml.etree.ElementTree模块实现了一个简单高效的 API,用于解析和创建 XML 数据。 一、说明 这是一个简短的使用教程xml.etree.ElementTree(ET简而言之)。目标是演示该模块的一些构建块和基…

Javaweb之javascript的DOM对象的详细解析

1.5.3 DOM对象 1.5.3.1 DOM介绍 DOM:Document Object Model 文档对象模型。也就是 JavaScript 将 HTML 文档的各个组成部分封装为对象。 DOM 其实我们并不陌生,之前在学习 XML 就接触过,只不过 XML 文档中的标签需要我们写代码解析&#x…

[PHP]Kodexplorer可道云 v4.47

KodExplorer可道云,原名芒果云,是基于Web技术的私有云和在线文件管理系统,由上海岱牧网络有限公司开发,发布于2012年6月。致力于为用户提供安全可控、可靠易用、高扩展性的私有云解决方案。 用户只需通过简单环境搭建,…

虚幻引擎:如何进行关卡切换?无缝切换?

一丶非无缝切换 在切换的时候会先断开连接,等创建好后才会链接,造成体验差 蓝图中用到的节点是 Execute Console Command 二丶无缝切换 链接的时候不会断开连接,中间不会出现卡顿,携带数据转换地图 1.需要在gamemode里面开启无缝漫游,开启之后使用上面的切换方式就可以做到无缝…

ESP32 C3 smartconfig一键配网报错

AP配网 在调试我的esp32c3的智能配网过程中,发现ap配网使用云智能App是可以正常配置的。 切记用户如果在menu菜单里使能AP配网,默认SSID名字为adh_PK值_MAC后6位。用户可以修改这个apssid的键值,但是要使用云智能app则这个名字的开头必须为ad…

什么是Amazon Simple Email Service(SES 群发邮件)

Amazon Simple Email Service(Amazon SES)让您可以使用 Amazon SES API 或 SMTP 接口放心地联络到客户,而无需使用本地简单邮件传输协议(Simple Mail Transfer Protocol,SMTP)电子邮件服务器。 目录 什么是…