|
|
--- |
|
|
license: apache-2.0 |
|
|
tags: |
|
|
- RyzenAI |
|
|
- Int8 quantization |
|
|
- Face Restoration |
|
|
- PSFRGAN |
|
|
- ONNX |
|
|
- Computer Vision |
|
|
metrics: |
|
|
- PSNR |
|
|
- MS_SSIM |
|
|
- FID |
|
|
--- |
|
|
|
|
|
# PSFRGAN for face restoration |
|
|
|
|
|
The model operates at 512x512 resolution and is particularly effective at restoring faces with various degradations including blur, noise, and low resolution. |
|
|
|
|
|
It was introduced in the paper _Progressive Semantic-Aware Style Transformation for Blind Face Restoration_ by Chaofeng Chen et al. at CVPR 2021. |
|
|
|
|
|
We have developed a modified version optimized for [AMD Ryzen AI](https://onnxruntime.ai/docs/execution-providers/Vitis-AI-ExecutionProvider.html). |
|
|
|
|
|
## Model description |
|
|
|
|
|
PSFRGAN (Progressive Semantic-aware Face Restoration Generative Adversarial Network) is a deep learning model designed for blind face restoration, capable of recovering high-quality face images from severely degraded inputs. |
|
|
|
|
|
## Intended uses & limitations |
|
|
|
|
|
You can use this model for face restoration tasks. See the [model hub](https://huggingface.co/models?search=amd/ryzenai-psfrgan) for all available psfrgan models. |
|
|
|
|
|
## How to use |
|
|
|
|
|
### Installation |
|
|
|
|
|
```bash |
|
|
# inference only |
|
|
pip install -r requirements-infer.txt |
|
|
# inference & evaluation |
|
|
pip install -r requirements-eval.txt |
|
|
``` |
|
|
|
|
|
### Data Preparation (optional: for evaluation) |
|
|
|
|
|
1. Download `CelebA-Test (LQ)` and `CelebA-Test (HQ)` from [GFP-GAN homepage](https://xinntao.github.io/projects/gfpgan) |
|
|
2. Organize the dataset directory as follows: |
|
|
|
|
|
```Plain |
|
|
βββ datasets |
|
|
βββ celeba_512_validation |
|
|
βββ 00000000.png |
|
|
βββ ... |
|
|
βββ celeba_512_validation_lq |
|
|
βββ 00000000.png |
|
|
βββ ... |
|
|
|
|
|
``` |
|
|
|
|
|
### Test & Evaluation |
|
|
|
|
|
- **Run inference on images** |
|
|
|
|
|
```bash |
|
|
python onnx_inference.py --onnx psfrgan_nchw_fp32.onnx --latent latent.npy --input /Path/To/Image --out-dir outputs |
|
|
python onnx_inference.py --onnx psfrgan_nhwc_int8.onnx --latent latent.npy --input /Path/To/Image --out-dir outputs |
|
|
``` |
|
|
|
|
|
_Arguments:_ |
|
|
|
|
|
`--input`: Accepts either a single image file path or a directory path. If it's a file, the script will process that image only. If it's a directory, the script will recursively scan for .png, .jpg, and .jpeg files and process all of them. |
|
|
|
|
|
`--latent`: (Optional) Path to the latent code file (.npy). If not provided, random latent values will be generated with a fixed seed for reproducibility. |
|
|
|
|
|
`--out-dir`: Output directory where the restored images will be saved. |
|
|
|
|
|
- **Evaluate the quantized model** |
|
|
|
|
|
```bash |
|
|
# eval fp32 |
|
|
python onnx_eval.py \ |
|
|
--onnx psfrgan_nchw_fp32.onnx \ |
|
|
--latent latent.npy \ |
|
|
--hq-dir datasets/celeba_512_validation \ |
|
|
--lq-dir datasets/celeba_512_validation_lq \ |
|
|
--out-dir outputs/fp32 -clean |
|
|
|
|
|
# eval int8 |
|
|
python onnx_eval.py \ |
|
|
--onnx psfrgan_nhwc_int8.onnx \ |
|
|
--latent latent.npy \ |
|
|
--hq-dir datasets/celeba_512_validation \ |
|
|
--lq-dir datasets/celeba_512_validation_lq \ |
|
|
--out-dir outputs/int8 -clean |
|
|
``` |
|
|
|
|
|
### Performance |
|
|
|
|
|
| Model | PSNR(β) | MS_SSIM(β) | FID(β) | |
|
|
| -------------- | ------- | ---------- | ------ | |
|
|
| PSFRGAN (fp32) | 25.27 | 0.8500 | 21.99 | |
|
|
| PSFRGAN (int8) | 25.27 | 0.8487 | 24.34 | |
|
|
|
|
|
--- |
|
|
|
|
|
```bibtex |
|
|
@inproceedings{ChenPSFRGAN, |
|
|
author = {Chen, Chaofeng and Li, Xiaoming and Lingbo, Yang and Lin, Xianhui and Zhang, Lei and Wong, Kwan-Yee~K.}, |
|
|
title = {Progressive Semantic-Aware Style Transformation for Blind Face Restoration}, |
|
|
Journal = {IEEE Conference on Computer Vision and Pattern Recognition (CVPR)}, |
|
|
year = {2021} |
|
|
} |
|
|
``` |
|
|
|