# Old Photo Restoration (Official PyTorch Implementation)
<img src='imgs/0001.jpg'/>
### [Project Page](http://raywzy.com/Old_Photo/) | [Paper (CVPR version)](https://arxiv.org/abs/2004.09484) | [Paper (Journal version)](https://arxiv.org/pdf/2009.07047v1.pdf) | [Pretrained Model](https://hkustconnect-my.sharepoint.com/:f:/g/personal/bzhangai_connect_ust_hk/Em0KnYOeSSxFtp4g_dhWdf0BdeT3tY12jIYJ6qvSf300cA?e=nXkJH2) | [Colab Demo](https://colab.research.google.com/drive/1NEm6AsybIiC5TwTU_4DqDkQO0nFRB-uA?usp=sharing) | [Replicate Demo & Docker Image](https://replicate.ai/zhangmozhe/bringing-old-photos-back-to-life) :fire:
**Bringing Old Photos Back to Life, CVPR2020 (Oral)**
**Old Photo Restoration via Deep Latent Space Translation, TPAMI 2022**
[Ziyu Wan](http://raywzy.com/)<sup>1</sup>,
[Bo Zhang](https://www.microsoft.com/en-us/research/people/zhanbo/)<sup>2</sup>,
[Dongdong Chen](http://www.dongdongchen.bid/)<sup>3</sup>,
[Pan Zhang](https://panzhang0212.github.io/)<sup>4</sup>,
[Dong Chen](https://www.microsoft.com/en-us/research/people/doch/)<sup>2</sup>,
[Jing Liao](https://liaojing.github.io/html/)<sup>1</sup>,
[Fang Wen](https://www.microsoft.com/en-us/research/people/fangwen/)<sup>2</sup> <br>
<sup>1</sup>City University of Hong Kong, <sup>2</sup>Microsoft Research Asia, <sup>3</sup>Microsoft Cloud AI, <sup>4</sup>USTC
<!-- ## Notes of this project
The code originates from our research project and the aim is to demonstrate the research idea, so we have not optimized it from a product perspective. And we will spend time to address some common issues, such as out of memory issue, limited resolution, but will not involve too much in engineering problems, such as speedup of the inference, fastapi deployment and so on. **We welcome volunteers to contribute to this project to make it more usable for practical application.** -->
## :sparkles: News
**2022.3.31**: Our new work regarding old film restoration will be published in CVPR 2022. For more details, please refer to the [project website](http://raywzy.com/Old_Film/) and [github repo](https://github.com/raywzy/Bringing-Old-Films-Back-to-Life).
The framework now supports the restoration of high-resolution input.
<img src='imgs/HR_result.png'>
Training code is available and welcome to have a try and learn the training details.
You can now play with our [Colab](https://colab.research.google.com/drive/1NEm6AsybIiC5TwTU_4DqDkQO0nFRB-uA?usp=sharing) and try it on your photos.
## Requirement
The code is tested on Ubuntu with Nvidia GPUs and CUDA installed. Python>=3.6 is required to run the code.
## Installation
Clone the Synchronized-BatchNorm-PyTorch repository for
```
cd Face_Enhancement/models/networks/
git clone https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .
cd ../../../
```
```
cd Global/detection_models
git clone https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .
cd ../../
```
Download the landmark detection pretrained model
```
cd Face_Detection/
wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
bzip2 -d shape_predictor_68_face_landmarks.dat.bz2
cd ../
```
Download the pretrained model, put the file `Face_Enhancement/checkpoints.zip` under `./Face_Enhancement`, and put the file `Global/checkpoints.zip` under `./Global`. Then unzip them respectively.
```
cd Face_Enhancement/
wget https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/face_checkpoints.zip
unzip face_checkpoints.zip
cd ../
cd Global/
wget https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life/releases/download/v1.0/global_checkpoints.zip
unzip global_checkpoints.zip
cd ../
```
Install dependencies:
```bash
pip install -r requirements.txt
```
## :rocket: How to use?
**Note**: GPU can be set 0 or 0,1,2 or 0,2; use -1 for CPU
### 1) Full Pipeline
You could easily restore the old photos with one simple command after installation and downloading the pretrained model.
For images without scratches:
```
python run.py --input_folder [test_image_folder_path] \
--output_folder [output_path] \
--GPU 0
```
For scratched images:
```
python run.py --input_folder [test_image_folder_path] \
--output_folder [output_path] \
--GPU 0 \
--with_scratch
```
**For high-resolution images with scratches**:
```
python run.py --input_folder [test_image_folder_path] \
--output_folder [output_path] \
--GPU 0 \
--with_scratch \
--HR
```
Note: Please try to use the absolute path. The final results will be saved in `./output_path/final_output/`. You could also check the produced results of different steps in `output_path`.
### 2) Scratch Detection
Currently we don't plan to release the scratched old photos dataset with labels directly. If you want to get the paired data, you could use our pretrained model to test the collected images to obtain the labels.
```
cd Global/
python detection.py --test_path [test_image_folder_path] \
--output_dir [output_path] \
--input_size [resize_256|full_size|scale_256]
```
<img src='imgs/scratch_detection.png'>
### 3) Global Restoration
A triplet domain translation network is proposed to solve both structured degradation and unstructured degradation of old photos.
<p align="center">
<img src='imgs/pipeline.PNG' width="50%" height="50%"/>
</p>
```
cd Global/
python test.py --Scratch_and_Quality_restore \
--test_input [test_image_folder_path] \
--test_mask [corresponding mask] \
--outputs_dir [output_path]
python test.py --Quality_restore \
--test_input [test_image_folder_path] \
--outputs_dir [output_path]
```
<img src='imgs/global.png'>
### 4) Face Enhancement
We use a progressive generator to refine the face regions of old photos. More details could be found in our journal submission and `./Face_Enhancement` folder.
<p align="center">
<img src='imgs/face_pipeline.jpg' width="60%" height="60%"/>
</p>
<img src='imgs/face.png'>
> *NOTE*:
> This repo is mainly for research purpose and we have not yet optimized the running performance.
>
> Since the model is pretrained with 256*256 images, the model may not work ideally for arbitrary resolution.
### 5) GUI
A user-friendly GUI which takes input of image by user and shows result in respective window.
#### How it works:
1. Run GUI.py file.
2. Click browse and select your image from test_images/old_w_scratch folder to remove scratches.
3. Click Modify Photo button.
4. Wait for a while and see results on GUI window.
5. Exit window by clicking Exit Window and get your result image in output folder.
<img src='imgs/gui.PNG'>
## How to train?
### 1) Create Training File
Put the folders of VOC dataset, collected old photos (e.g., Real_L_old and Real_RGB_old) into one shared folder. Then
```
cd Global/data/
python Create_Bigfile.py
```
Note: Remember to modify the code based on your own environment.
### 2) Train the VAEs of domain A and domain B respectively
```
cd ..
python train_domain_A.py --use_v2_degradation --continue_train --training_dataset domain_A --name domainA_SR_old_photos --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 100 --no_html --gpu_ids 0,1,2,3 --self_gen --nThreads 4 --n_downsample_global 3 --k_size 4 --use_v2 --mc 64 --start_r 1 --kl 1 --no_cgan --outputs_dir [your_output_folder] --checkpoints_dir [your_ckpt_folder]
python train_domain_B.py --continue_train --training_dataset domain_B --name domainB_old_photos --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 120 --no_html --gpu_ids 0,1,2,3 --self_gen --nThreads 4 --n_downsample_global 3 --k_
没有合适的资源?快使用搜索试试~ 我知道了~
Bringing-Old-Photos-Back-to-Life(打包版)
共86个文件
py:43个
pyc:20个
pth:18个
需积分: 0 1 下载量 92 浏览量
2023-11-01
16:14:43
上传
评论
收藏 865.03MB ZIP 举报
温馨提示
微软老照片修复
资源推荐
资源详情
资源评论
收起资源包目录
Bringing-Old-Photos-Back-to-Life(打包).zip (86个子文件)
Bringing-Old-Photos-Back-to-Life
SECURITY.md 3KB
test_images
old_w_scratch
old
LICENSE 1KB
predict.py 8KB
Face_Enhancement
data
__pycache__
options
__pycache__
models
networks
sync_batchnorm
__pycache__
__pycache__
__pycache__
checkpoints
Setting_9_epoch_100
FaceSR_512
util
__pycache__
output
stage_3_face_output
each_img
stage_2_detection_output
final_output
stage_1_restore_output
input_image
masks
input
mask
restored_image
origin
Face_Detection
run.py 7KB
requirements.txt 136B
GUI.py 7KB
kubernetes-pod.yml 727B
imgs
README.md 12KB
Global
train_mapping.py 6KB
train_domain_A.py 5KB
detection.py 5KB
data
__init__.py 0B
online_dataset_for_old_photos.py 15KB
base_data_loader.py 268B
base_dataset.py 4KB
data_loader.py 302B
image_folder.py 2KB
Create_Bigfile.py 2KB
Load_Bigfile.py 2KB
custom_dataset_data_loader.py 1KB
options
__init__.py 0B
train_options.py 5KB
test_options.py 4KB
base_options.py 16KB
__pycache__
__init__.cpython-310.pyc 194B
base_options.cpython-310.pyc 9KB
test_options.cpython-310.pyc 3KB
train_domain_B.py 5KB
detection_models
__init__.py 0B
sync_batchnorm
__init__.py 547B
batchnorm_reimpl.py 2KB
comm.py 4KB
batchnorm.py 16KB
unittest.py 768B
replicate.py 3KB
__pycache__
__init__.cpython-310.pyc 544B
comm.cpython-310.pyc 5KB
replicate.cpython-310.pyc 3KB
batchnorm.cpython-310.pyc 15KB
networks.py 11KB
antialiasing.py 2KB
__pycache__
__init__.cpython-310.pyc 203B
antialiasing.cpython-310.pyc 2KB
networks.cpython-310.pyc 9KB
models
__init__.py 0B
networks.py 30KB
models.py 1KB
mapping_model.py 13KB
base_model.py 4KB
pix2pixHD_model_DA.py 16KB
pix2pixHD_model.py 15KB
NonLocal_feature_mapping_model.py 6KB
__pycache__
__init__.cpython-310.pyc 193B
base_model.cpython-310.pyc 4KB
NonLocal_feature_mapping_model.cpython-310.pyc 4KB
networks.cpython-310.pyc 19KB
mapping_model.cpython-310.pyc 9KB
models.cpython-310.pyc 946B
checkpoints
detection
label2city
restoration
VAE_B_quality
latest_net_G.pth 3.34MB
latest_optimizer_G.pth 6.67MB
latest_optimizer_D.pth 42.19MB
latest_net_D.pth 21.1MB
mapping_scratch
latest_optimizer_mapping_net.pth 391.75MB
latest_optimizer_D.pth 42.24MB
latest_net_mapping_net.pth 195.88MB
latest_net_D.pth 21.25MB
mapping_quality
VAE_A_quality
latest_net_G.pth 3.34MB
latest_optimizer_featD.pth 21.57MB
latest_optimizer_G.pth 6.67MB
latest_net_featD.pth 10.79MB
latest_optimizer_D.pth 42.19MB
latest_net_D.pth 21.1MB
mapping_Patch_Attention
VAE_B_scratch
latest_net_G.pth 3.34MB
latest_optimizer_G.pth 6.67MB
latest_optimizer_D.pth 42.19MB
latest_net_D.pth 21.1MB
test.py 6KB
util
__init__.py 0B
util.py 2KB
image_pool.py 1KB
visualizer.py 6KB
__pycache__
util.cpython-310.pyc 2KB
__init__.cpython-310.pyc 191B
image_pool.cpython-310.pyc 1KB
detection_util
util.py 8KB
__pycache__
util.cpython-310.pyc 8KB
共 86 条
- 1
资源评论
阿虚同学
- 粉丝: 1099
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功