{"id":17225659,"url":"https://github.com/chaofengc/face-sparnet","last_synced_at":"2026-03-17T12:06:13.658Z","repository":{"id":43081856,"uuid":"230259246","full_name":"chaofengc/Face-SPARNet","owner":"chaofengc","description":"Pytorch codes for \"Learning Spatial Attention for Face Super-Resolution\",  TIP 2021.","archived":false,"fork":false,"pushed_at":"2025-02-20T06:05:57.000Z","size":7363,"stargazers_count":222,"open_issues_count":4,"forks_count":23,"subscribers_count":10,"default_branch":"master","last_synced_at":"2026-03-05T19:40:58.926Z","etag":null,"topics":["face-super-resolution","spatial-attention"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chaofengc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-26T12:18:31.000Z","updated_at":"2025-11-06T11:32:35.000Z","dependencies_parsed_at":"2024-05-29T09:10:55.121Z","dependency_job_id":"a8bb7d1e-5cdd-4090-abd1-49cb4e6a6af9","html_url":"https://github.com/chaofengc/Face-SPARNet","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/chaofengc/Face-SPARNet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FFace-SPARNet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FFace-SPARNet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FFace-SPARNet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FFace-SPARNet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chaofengc","download_url":"https://codeload.github.com/chaofengc/Face-SPARNet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FFace-SPARNet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30623527,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T11:26:08.186Z","status":"ssl_error","status_checked_at":"2026-03-17T11:24:37.311Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["face-super-resolution","spatial-attention"],"created_at":"2024-10-15T04:14:09.984Z","updated_at":"2026-03-17T12:06:13.635Z","avatar_url":"https://github.com/chaofengc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SPARNet: Learning Spatial Attention for Face Super-Resolution in PyTorch \n\n[Learning Spatial Attention for Face Super-Resolution](http://arxiv.org/abs/2012.01211)  \n[**Chaofeng Chen**](https://chaofengc.github.io), [Dihong Gong](https://www.cise.ufl.edu/~dihong/), [Hao Wang](https://dblp.uni-trier.de/pid/w/HaoWang50.html), [Zhifeng Li](https://dblp.org/pid/56/2053.html), [Kwan-Yee K. Wong](https://i.cs.hku.hk/~kykwong/)\n\n![example result](example.gif)\n\n## Installation and Requirements \n\nClone this repository\n```\ngit clone https://github.com/chaofengc/Face-SPARNet.git\ncd Face-SPARNet\n```\n\nI have tested the codes on\n- Ubuntu 18.04\n- CUDA 10.1  \n- Python 3.7, install required packages by `pip3 install -r requirements.txt`  \n\n## Getting Started \n\n### Download Pretrain Models and Dataset\nDownload the pretrained models and data from the following link and put them to `./pretrain_models` and `./test_dirs` respectively\n- [Github](https://github.com/chaofengc/Face-SPARNet/releases/tag/v0.1.0)  \n- [BaiduNetDisk](https://pan.baidu.com/s/1zYimaAnIgMIKBf9KANpxog), extract code: `2nax`   \n\n### Test with Pretrained Models\n\nWe provide example test commands in script `test.sh` for both SPARNet and SPARNetHD. Two models with difference configurations are provided for each of them, refer to [section below](#differences-with-the-paper) to see the differences. Here are some test tips:\n\n- SPARNet upsample a 16x16 bicubic downsampled face image to 128x128, and there is **no need to align the LR face**.   \n- SPARNetHD enhance a low quality face image and generate high quality 512x512 outputs, and the LQ inputs **should be pre-aligned as FFHQ**.  \n- Please specify test input directory with `--dataroot` option.  \n- Please specify save path with `--save_as_dir`, otherwise the results will be saved to predefined directory `results/exp_name/test_latest`.  \n\nWe also provide command to crop and align faces from single image, and then paste them back, the same as [PSFRGAN](https://github.com/chaofengc/PSFRGAN) \n```\npython test_enhance_single_unalign.py --gpus 1 --model sparnethd --name SPARNetHD_V4_Attn2D \\\n    --res_depth 10 --att_name spar --Gnorm 'in' \\\n    --pretrain_model_path [./path/to/model/SPARNetHD_V4_Attn2D_net_H-epoch10.pth] \\\n    --test_img_path ./test_images/test_hzgg.jpg --results_dir test_hzgg_results\n```\n\n### Train the Model\n\nThe commands used to train the released models are provided in script `train.sh`. Here are some train tips:\n\n- You should download [CelebA](http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html) and [FFHQ](https://github.com/NVlabs/ffhq-dataset) to train SPARNet and SPARNetHD respectively. Please change the `--dataroot` to the path where your training images are stored.  \n- To train SPARNet, we simply crop out faces from CelebA without pre-alignment, because for ultra low resolution face SR, it is difficult to pre-align the LR images.  \n- Please change the `--name` option for different experiments. Tensorboard records with the same name will be moved to `check_points/log_archive`, and the weight directory will only store weight history of latest experiment with the same name.  \n- `--gpus` specify number of GPUs used to train. The script will use GPUs with more available memory first. To specify the GPU index, uncomment the `export CUDA_VISIBLE_DEVICES=` \n- SPARNetHD needs **at least 25GB memory to train with `batch_size=2`**. \n\n## Differences with the Paper\nSince the original codes are messed up, we rewrite the codes and retrain all models. This leads to slightly different results between the released model and those reported in the paper. Besides, we also extend the 2D spatial attention to 3D attention, and release some models with 3D attention. We list all of them below\n\n### SPARNet \n\nWe found that extending 2D spatial attention to 3D attention improves the performance a lot. We trained a light model with half parameter number by reducing the number of FAU blocks, denoted as SPARNet-Light-Attn3D. SPARNet-Light-Attn3D shows similar performance with SPARNet. We also released the model for your reference.   \n\n| Model          | DICNet      | SPARNet (in paper) | SPARNet (Released) | SPARNet-Light-Attn3D (Released) |\n| -----------    | ----------- | -----------        | -----------        | -----------                     |\n| #Params(M)     | 22.8        | 9.86               | 10.52              | 5.24                            |\n| PSNR (\u0026#8593;) | 26.73       | 26.97              | **27.43**          | 27.39                           |\n| SSIM (\u0026#8593;) | 0.7955      | 0.8026             | **0.8201**         | 0.8189                          |\n\n*All models are trained with CelebA and tested on Helen test set provided by [DICNet](https://github.com/Maclory/Deep-Iterative-Collaboration)*\n\n![example result](example_ultra_facesrx8.png)\n\n### SPARNetHD\n\nWe also provide network with 2D and 3D attention for SPARNetHD. For the test dataset, we clean up non-face images, add some extra test images from internet, and obtain a new CelebA-TestN dataset with 1117 images. We test the retrained model on the new dataset and recalculate the FID scores.\n\nSimilar as StyleGAN, we use the exponential moving average weight as the final model, which shows slightly better results.\n\n| Model         | SPARNetHD (in paper) | SPARNetHD-Attn2D (Released) | SPARNetHD-Attn3D (Released) |\n| -----------   | -----------          | -----------                 | -----------                 |\n| FID (\u0026#8595;) | 27.16                | **26.72**                   | 28.42                       |\n\n\n## Citation\n```bib\n@ARTICLE{ChenSPARNet,\n      author = {Chen, Chaofeng and Gong, Dihong and Wang, Hao and Li, Zhifeng and Wong, Kwan-Yee~K.},\n      journal={IEEE Transactions on Image Processing}, \n      title={Learning Spatial Attention for Face Super-Resolution}, \n      year={2021},\n      volume={30},\n      number={},\n      pages={1219-1231},\n      doi={10.1109/TIP.2020.3043093}\n}\n\n```\n\n## License\n\n\u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-sa/4.0/\"\u003e\u003cimg alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png\" /\u003e\u003c/a\u003e\u003cbr /\u003eThis work is licensed under a \u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-sa/4.0/\"\u003eCreative Commons Attribution-NonCommercial-ShareAlike 4.0 International License\u003c/a\u003e.\n\n## Acknowledgement\n\nThe codes are based on [CycleGAN](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix). The project also benefits from [DICNet](https://github.com/Maclory/Deep-Iterative-Collaboration).  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaofengc%2Fface-sparnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaofengc%2Fface-sparnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaofengc%2Fface-sparnet/lists"}