{"id":17225668,"url":"https://github.com/chaofengc/psfrgan","last_synced_at":"2025-04-05T16:11:01.859Z","repository":{"id":40688005,"uuid":"296362408","full_name":"chaofengc/PSFRGAN","owner":"chaofengc","description":"PyTorch codes for \"Progressive Semantic-Aware Style Transformation for Blind Face Restoration\", CVPR2021","archived":false,"fork":false,"pushed_at":"2024-07-10T01:40:36.000Z","size":9428,"stargazers_count":377,"open_issues_count":4,"forks_count":69,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-03-29T15:09:56.639Z","etag":null,"topics":["enhanced-faces","face","super-resolution"],"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":"2020-09-17T15:10:26.000Z","updated_at":"2025-02-23T09:53:40.000Z","dependencies_parsed_at":"2024-10-29T18:35:40.505Z","dependency_job_id":null,"html_url":"https://github.com/chaofengc/PSFRGAN","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FPSFRGAN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FPSFRGAN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FPSFRGAN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaofengc%2FPSFRGAN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chaofengc","download_url":"https://codeload.github.com/chaofengc/PSFRGAN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361695,"owners_count":20926643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["enhanced-faces","face","super-resolution"],"created_at":"2024-10-15T04:14:11.029Z","updated_at":"2025-04-05T16:11:01.829Z","avatar_url":"https://github.com/chaofengc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PSFR-GAN in PyTorch \n\n[Progressive Semantic-Aware Style Transformation for Blind Face Restoration](https://arxiv.org/abs/2009.08709)  \n[Chaofeng Chen](https://chaofengc.github.io), [Xiaoming Li](https://csxmli2016.github.io/), [Lingbo Yang](https://lotayou.github.io), [Xianhui Lin](https://dblp.org/pid/147/7708.html), [Lei Zhang](https://www4.comp.polyu.edu.hk/~cslzhang/), [Kwan-Yee K. Wong](https://i.cs.hku.hk/~kykwong/)\n\n![](test_dir/test_hzgg.jpg)\n![](test_hzgg_results/hq_final.jpg)\n\n### Changelog \n- **2021.04.26**: Add pytorch vgg19 model to GoogleDrive and remove `--distributed` option which causes training error.\n- **2021.03.22**: Update new model at 15 epoch (52.5k iterations).\n- **2021.03.19**: Add train codes for PSFRGAN and FPN.\n\n## Prerequisites and Installation\n- Ubuntu 18.04\n- CUDA 10.1  \n- Clone this repository\n    ```\n    git clone https://github.com/chaofengc/PSFR-GAN.git\n    cd PSFR-GAN\n    ```\n- Python 3.7, install required packages by `pip3 install -r requirements.txt`  \n\n## Quick Test\n\n### Download Pretrain Models and Dataset\nDownload the pretrained models from the following link and put them to `./pretrain_models`  \n- [Github](https://github.com/chaofengc/PSFRGAN/releases/tag/v0.1.0)\n- [BaiduNetDisk](https://pan.baidu.com/s/1cru3uUASEfGX6p6L0_7gWQ), extract code: `gj2r`\n\n### Test single image\nRun the following script to enhance face(s) in single input  \n```\npython test_enhance_single_unalign.py --test_img_path ./test_dir/test_hzgg.jpg --results_dir test_hzgg_results --gpus 1\n```\n\nThis script do the following things:\n- Crop and align all the faces from input image, stored at `results_dir/LQ_faces`  \n- Parse these faces and then enhance them, results stored at `results_dir/ParseMaps` and `results_dir/HQ`  \n- Paste then enhanced faces back to the original image `results_dir/hq_final.jpg`  \n- You can use `--gpus` to specify how many GPUs to use, `\u003c=0` means running on CPU. The program will use GPU with the most available memory. Set `CUDA_VISIBLE_DEVICE` to specify the GPU if you do not want automatic GPU selection.  \n\n### Test image folder \nTo test multiple images, we first crop out all the faces and align them use the following script.  \n```\npython align_and_crop_dir.py --src_dir test_dir --results_dir test_dir_align_results\n```  \n\nFor images (*e.g.* `multiface_test.jpg`) contain multiple faces, the aligned faces will be stored as `multiface_test_{face_index}.jpg`  \nAnd then parse the aligned faces and enhance them with  \n```\npython test_enhance_dir_align.py --src_dir test_dir_align_results --results_dir test_dir_enhance_results\n```  \nResults will be saved to three folders respectively: `results_dir/lq`, `results_dir/parse`, `results_dir/hq`.   \n\n### Additional test script\n\nFor your convenience, we also provide script to test multiple unaligned images and paste the enhance results back. **Note the paste back operation could be quite slow for large size images containing many faces (dlib takes time to detect faces in large image).**\n```\npython test_enhance_dir_unalign.py --src_dir test_dir --results_dir test_unalign_results\n```  \nThis script basically do the same thing as `test_enhance_single_unalign.py` for each image in `src_dir`\n\n## Train the Model\n\n### Data Preparation\n\n- Download [FFHQ](https://github.com/NVlabs/ffhq-dataset) and put the images to `../datasets/FFHQ/imgs1024`\n- Download parsing masks (`512x512`) [HERE](https://drive.google.com/file/d/1eQwO8hKcaluyCnxuZAp0eJVOdgMi30uA/view?usp=sharing) generated by the pretrained FPN and put them to `../datasets/FFHQ/masks512`.\n\n*Note: you may change `../datasets/FFHQ` to your own path. But images and masks must be stored under `your_own_path/imgs1024` and `your_own_path/masks512` respectively.*\n\n### Train Script for PSFRGAN\n\nHere is an example train script for PSFRGAN:\n\n```\npython train.py --gpus 2 --model enhance --name PSFRGAN_v001 \\\n    --g_lr 0.0001 --d_lr 0.0004 --beta1 0.5 \\\n    --gan_mode 'hinge' --lambda_pix 10 --lambda_fm 10 --lambda_ss 1000 \\\n    --Dinput_nc 22 --D_num 3 --n_layers_D 4 \\\n    --batch_size 2 --dataset ffhq  --dataroot ../datasets/FFHQ \\\n    --visual_freq 100 --print_freq 10 #--continue_train\n```\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, use `export CUDA_VISIBLE_DEVICES=your_gpu_ids` before the script.\n- Uncomment `--continue_train` to resume training. *Current codes do not resume the optimizer state.* \n- It needs at least **8GB** memory to train with **batch_size=1**. \n\n### Scripts for FPN\n\nYou may also train your own FPN and generate masks for the HQ images by yourself with the following steps: \n\n- Download [CelebAHQ-Mask](https://github.com/switchablenorms/CelebAMask-HQ) dataset. Generate `CelebAMask-HQ-mask` and `CelebAMask-HQ-mask-color` with the provided scripts in `CelebAMask-HQ/face_parsing/Data_preprocessing/`.\n- Train FPN with the following commmand\n```\npython train.py --gpus 1 --model parse --name FPN_v001 \\\n    --lr 0.0002 --batch_size 8 \\\n    --dataset celebahqmask --dataroot ../datasets/CelebAMask-HQ \\\n    --visual_freq 100 --print_freq 10 #--continue_train\n```\n- Generate parsing masks with your own FPN using the following command:\n```\npython generate_masks.py --save_masks_dir ../datasets/FFHQ/masks512 --batch_size 8 --parse_net_weight path/to/your/own/FPN \n```\n\n## Citation\n```\n@inproceedings{ChenPSFRGAN,\n    author = {Chen, Chaofeng and Li, Xiaoming and Lingbo, Yang and Lin, Xianhui and Zhang, Lei and Wong, Kwan-Yee~K.},\n    title = {Progressive Semantic-Aware Style Transformation for Blind Face Restoration},\n    Journal = {IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},\n    year = {2021}\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\nThis work is inspired by [SPADE](https://github.com/NVlabs/SPADE), and closed related to [DFDNet](https://github.com/csxmli2016/DFDNet) and [HiFaceGAN](https://github.com/Lotayou/Face-Renovation). Our codes largely benefit from [CycleGAN](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaofengc%2Fpsfrgan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaofengc%2Fpsfrgan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaofengc%2Fpsfrgan/lists"}