GithubHelp home page GithubHelp logo

microsoft / bringing-old-photos-back-to-life Goto Github PK

View Code? Open in Web Editor NEW
14.4K 283.0 1.9K 40.91 MB

Bringing Old Photo Back to Life (CVPR 2020 oral)

Home Page: https://arxiv.org/abs/2004.09484

License: MIT License

Python 99.35% Dockerfile 0.40% Shell 0.25%
image-restoration old-photo-restoration generative-adversarial-network gans pytorch image-manipulation photo-restoration photos

bringing-old-photos-back-to-life's Introduction

Old Photo Restoration (Official PyTorch Implementation)

Bringing Old Photos Back to Life, CVPR2020 (Oral)

Old Photo Restoration via Deep Latent Space Translation, TPAMI 2022

Ziyu Wan1, Bo Zhang2, Dongdong Chen3, Pan Zhang4, Dong Chen2, Jing Liao1, Fang Wen2
1City University of Hong Kong, 2Microsoft Research Asia, 3Microsoft Cloud AI, 4USTC

✨ 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 and github repo.

The framework now supports the restoration of high-resolution input.

Training code is available and welcome to have a try and learn the training details.

You can now play with our Colab 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:

pip install -r requirements.txt

🚀 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]

3) Global Restoration

A triplet domain translation network is proposed to solve both structured degradation and unstructured degradation of old photos.

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]

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.

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.

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_size 4 --use_v2 --mc 64 --start_r 1 --kl 1 --no_cgan --outputs_dir [your_output_folder]  --checkpoints_dir [your_ckpt_folder]

Note: For the --name option, please ensure your experiment name contains "domainA" or "domainB", which will be used to select different dataset.

3) Train the mapping network between domains

Train the mapping without scratches:

python train_mapping.py --use_v2_degradation --training_dataset mapping --use_vae_which_epoch 200 --continue_train --name mapping_quality --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 80 --no_html --gpu_ids 0,1,2,3 --nThreads 8 --load_pretrainA [ckpt_of_domainA_SR_old_photos] --load_pretrainB [ckpt_of_domainB_old_photos] --l2_feat 60 --n_downsample_global 3 --mc 64 --k_size 4 --start_r 1 --mapping_n_block 6 --map_mc 512 --use_l1_feat --niter 150 --niter_decay 100 --outputs_dir [your_output_folder] --checkpoints_dir [your_ckpt_folder]

Traing the mapping with scraches:

python train_mapping.py --no_TTUR --NL_res --random_hole --use_SN --correlation_renormalize --training_dataset mapping --NL_use_mask --NL_fusion_method combine --non_local Setting_42 --use_v2_degradation --use_vae_which_epoch 200 --continue_train --name mapping_scratch --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 36 --no_html --gpu_ids 0,1,2,3 --nThreads 8 --load_pretrainA [ckpt_of_domainA_SR_old_photos] --load_pretrainB [ckpt_of_domainB_old_photos] --l2_feat 60 --n_downsample_global 3 --mc 64 --k_size 4 --start_r 1 --mapping_n_block 6 --map_mc 512 --use_l1_feat --niter 150 --niter_decay 100 --outputs_dir [your_output_folder] --checkpoints_dir [your_ckpt_folder] --irregular_mask [absolute_path_of_mask_file]

Traing the mapping with scraches (Multi-Scale Patch Attention for HR input):

python train_mapping.py --no_TTUR --NL_res --random_hole --use_SN --correlation_renormalize --training_dataset mapping --NL_use_mask --NL_fusion_method combine --non_local Setting_42 --use_v2_degradation --use_vae_which_epoch 200 --continue_train --name mapping_Patch_Attention --label_nc 0 --loadSize 256 --fineSize 256 --dataroot [your_data_folder] --no_instance --resize_or_crop crop_only --batchSize 36 --no_html --gpu_ids 0,1,2,3 --nThreads 8 --load_pretrainA [ckpt_of_domainA_SR_old_photos] --load_pretrainB [ckpt_of_domainB_old_photos] --l2_feat 60 --n_downsample_global 3 --mc 64 --k_size 4 --start_r 1 --mapping_n_block 6 --map_mc 512 --use_l1_feat --niter 150 --niter_decay 100 --outputs_dir [your_output_folder] --checkpoints_dir [your_ckpt_folder] --irregular_mask [absolute_path_of_mask_file] --mapping_exp 1

Citation

If you find our work useful for your research, please consider citing the following papers :)

@inproceedings{wan2020bringing,
title={Bringing Old Photos Back to Life},
author={Wan, Ziyu and Zhang, Bo and Chen, Dongdong and Zhang, Pan and Chen, Dong and Liao, Jing and Wen, Fang},
booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
pages={2747--2757},
year={2020}
}
@article{wan2020old,
  title={Old Photo Restoration via Deep Latent Space Translation},
  author={Wan, Ziyu and Zhang, Bo and Chen, Dongdong and Zhang, Pan and Chen, Dong and Liao, Jing and Wen, Fang},
  journal={arXiv preprint arXiv:2009.07047},
  year={2020}
}

If you are also interested in the legacy photo/video colorization, please refer to this work.

Maintenance

This project is currently maintained by Ziyu Wan and is for academic research use only. If you have any questions, feel free to contact [email protected].

License

The codes and the pretrained model in this repository are under the MIT license as specified by the LICENSE file. We use our labeled dataset to train the scratch detection model.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

bringing-old-photos-back-to-life's People

Contributors

aayush-hub avatar chenxwh avatar codeandmedia avatar davvid avatar hijak avatar leetaogoooo avatar m-ahadi avatar microsoftopensource avatar p1x31 avatar raywzy avatar samiraguiar avatar zhangmozhe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bringing-old-photos-back-to-life's Issues

High Resolution Photos

Hi!

The code is working quite well! My only issue is for serious photo restoration it doesn't support higher resolution scans. I've been working on a workaround for this, but I was wondering if there was anything that could be done in a future iteration to help with higher resolution images?

I have split a larger photo into smaller images and then re-stitched it together. Is there anyway I can get the code to run on one large image so the color is consistent and no photo detail is lost?

I've included some examples of my workaround.
Original:
Picture2

'Stitched'
Stitched

Lower resolution (full image)
507a96fc-9b9d-4d15-b8b9-fb5f864d0efc

Unknown CUDA error although everything is set up properly

┌─[root@null]─[/home/null/Code/Python/Bringing-Old-Photos-Back-to-Life]
└──╼ #CUDA_VISIBLE_DEVICES=0 python run.py --input_folder /home/null/Desktop/test/ --output_folder /home/seq/Desktop/test_re/ --GPU 0
Running Stage 1: Overall restoration
Traceback (most recent call last):
  File "test.py", line 93, in <module>
    opt = TestOptions().parse(save=False)
  File "/home/null/Code/Python/Bringing-Old-Photos-Back-to-Life/Global/options/base_options.py", line 350, in parse
    torch.cuda.set_device(self.opt.gpu_ids[0])
  File "/usr/local/lib/python3.8/dist-packages/torch/cuda/__init__.py", line 263, in set_device
    torch._C._cuda_setDevice(device)
  File "/usr/local/lib/python3.8/dist-packages/torch/cuda/__init__.py", line 172, in _lazy_init
    torch._C._cuda_init()
RuntimeError: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero.
Traceback (most recent call last):
  File "run.py", line 91, in <module>
    for x in os.listdir(stage_1_results):
FileNotFoundError: [Errno 2] No such file or directory: '/home/null/Desktop/test_re/stage_1_restore_output/restored_image'
┌─[✗]─[root@null]─[/home/null/Code/Python/Bringing-Old-Photos-Back-to-Life]
└──╼ #nvidia-smi
Sun Nov 22 15:45:53 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.80.02    Driver Version: 450.80.02    CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce RTX 2070    On   | 00000000:01:00.0 Off |                  N/A |
| N/A   42C    P8     2W /  N/A |      6MiB /  7982MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1207      G   /usr/lib/xorg/Xorg                  4MiB |
+-----------------------------------------------------------------------------+

Has anyone else experienced this? Any suggestions for a solution here?

how to run code with CPU?

First of all, thank you for project. I was able to install on windows, but because my gpu doesnt have vram for large resolution images, (2-8MPx scanned archive photos), and cuda out of memory always, decided to try with pytorch for cpu. I have Ryzen 1700 CPU, and know that cpu mode is much slower, but have patience and will wait untill final output render. Saw that models updated to support cpu but dont know how to run code properly....Tried with modifications to run on cpu but without success.... please help :)
Thank you

Missing non-linearity between ResNet layers?

I'm sorry if I'm just being silly, but shouldn't there be a ReLU (or other non-linearity) between ResNet layers (after the add)? For example, the mapping net architecture looks like:
...
(10): InstanceNorm2d(512, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False)
(11): ReLU(inplace=True)
(12): ResnetBlock(
(conv_block): Sequential(
(0): ReflectionPad2d((1, 1, 1, 1))
(1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1))
(2): InstanceNorm2d(512, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False)
(3): ReLU(inplace=True)
(4): ReflectionPad2d((1, 1, 1, 1))
(5): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1))
(6): InstanceNorm2d(512, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False)
)
)
(13): ResnetBlock(
(conv_block): Sequential(
(0): ReflectionPad2d((1, 1, 1, 1))
(1): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1))
...

RuntimeError: Found no NVIDIA driver on your system

I have found this error when I try:
python run.py --input_folder /home/akenateb/Bringing-Old-Photos-Back-to-Life/imgs/ --output_folder /home/akenateb/Bringing-Old-Photos-Back-to-Life/imgs/output/ --GPU 0

Running Stage 1: Overall restoration Traceback (most recent call last): File "test.py", line 93, in <module> opt = TestOptions().parse(save=False) File "/root/photos/Bringing-Old-Photos-Back-to-Life/Global/options/base_options.py", line 350, in parse torch.cuda.set_device(self.opt.gpu_ids[0]) File "/root/anaconda3/lib/python3.8/site-packages/torch/cuda/__init__.py", line 263, in set_device torch._C._cuda_setDevice(device) File "/root/anaconda3/lib/python3.8/site-packages/torch/cuda/__init__.py", line 172, in _lazy_init torch._C._cuda_init() RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx

nvcc --version: vcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0

Any help?
Thanks in advance

Using CPU instead of CUDA

Is it possible to use CPU or even OpenCL instead? CUDA is nvidia proprietary code and I have an AMD laptop. Thanks.

[QUESTION] Colab images with scretches

I have added the --with_scratch option to the section

!python run.py --input_folder /content/photo_restoration/test_images/upload --output_folder /content/photo_restoration/upload_output --GPU 0 --with_scratch

in order to process images with scratches.
This is the result that I obtain:

Running Stage 1: Overall restoration
initializing the dataloader
model weights loaded
directory of testing image: /content/photo_restoration/test_images/upload
processing EMILIA 55.png
You are using NL + Res
Now you are processing EMILIA 55.png
Skip EMILIA 55.png
Finish Stage 1 ...


Running Stage 2: Face Detection
1
Finish Stage 2 ...


Running Stage 3: Face Enhancement
The main GPU is 
0
dataset [FaceTestDataset] of size 1 was created
The size of the latent vector size is [8,8]
Network [SPADEGenerator] was created. Total number of parameters: 92.1 million. To see the architecture, do print(network).
hi :)
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:3121: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
  "See the documentation of nn.Upsample for details.".format(mode))
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:1614: UserWarning: nn.functional.tanh is deprecated. Use torch.tanh instead.
  warnings.warn("nn.functional.tanh is deprecated. Use torch.tanh instead.")
Finish Stage 3 ...


Running Stage 4: Blending
Finish Stage 4 ...


All the processing is done. Please check the results.

and the image (I have intentionally obscured the face) for privacy:

Schermata_2020-09-19_alle_20_51_58

Is the pipeline command correct? Thank you!

Don't your scheme use the sampling method on inference?

I have been struggled to understand a good approach on your paper.
Then, I could not find the role of sampling to perform VAE on inference time as below.
Also, if you have only used the sampling function to define KL divergence on training step,
I can only think that it is hard to assume that the input of G corresponds to a normal distribution.
Because the collection of mean and std. does not have the characteristic of Gaussian distribution itself.
Can you clarify our mis-understanding or fix missing points?
I have no choice but to guess that the input of G is feature map only including mean and std. not samples from Gaussian prior. Right?

On paper "The VAEs assumes Gaussian prior
for the distribution of latent codes, so that images can be
reconstructed by sampling from the latent space. We use the
re-parameterization trick to enable differentiable stochastic
sampling"

def inference(self, label, inst):

input_concat = label.data.cuda()

label_feat = self.netG_A.forward(input_concat, flow="enc")

if self.opt.NL_use_mask:
    label_feat_map = self.mapping_net(label_feat.detach(), inst.cuda())
else:
    label_feat_map = self.mapping_net(label_feat.detach())

    fake_image = self.netG_B.forward(label_feat_map, flow="dec")
return fake_image

UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0.

hi ! i did try to run the code with no success using pytorch 1.4 and 1.6 with python 3 im running Ubuntu 18.04.5 LTS (GNU/Linux 5.4.0-1025-aws x86_64v) CUDA 10.1 and Intel MKL

but i always have the same results no FACES, is any advise to fix this issues ?

============================================================================

Running Stage 3: Face Enhancement
The main GPU is
0
dataset [FaceTestDataset] of size 12 was created
The size of the latent vector size is [8,8]
Network [SPADEGenerator] was created. Total number of parameters: 92.1 million. To see the architecture, do print(network).
hi :)
/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/functional.py:2506: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details.
"See the documentation of nn.Upsample for details.".format(mode))
/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/nn/functional.py:1340: UserWarning: nn.functional.tanh is deprecated. Use torch.tanh instead.
warnings.warn("nn.functional.tanh is deprecated. Use torch.tanh instead.")
Finish Stage 3 ...

Issues about why it always skips the images that I upload

Hi, recently I tried your Colab demo to restore some of my old images, but here comes the issue. When I follow the steps and run the code, it always prints skip the my uploaded images like the following shows:

Running Stage 1: Overall restoration
initializing the dataloader
model weights loaded
directory of testing image: /content/photo_restoration/test_images/upload
processing testScratch.png
You are using NL + Res
Now you are processing testScratch.png
Skip testScratch.png
Finish Stage 1 ...

Running Stage 2: Face Detection
Finish Stage 2 ...

Running Stage 3: Face Enhancement
The main GPU is
0
dataset [FaceTestDataset] of size 0 was created
The size of the latent vector size is [8,8]
Network [SPADEGenerator] was created. Total number of parameters: 92.1 million. To see the architecture, do print(network).
hi :)
Finish Stage 3 ...

Running Stage 4: Blending
Finish Stage 4 ...

All the processing is done. Please check the results.

Therefore, I'd like to know whether there are any requirements that the uploaded images have to satisfy or did I make some mistakes ? Thanks a lot.

python: can't open file 'test.py': [Errno 2] No such file or directory

Installation went fine, all my folders have been created
I'm running Python 3.6.3 :: Anaconda custom (64-bit) in Ubuntu
After I run:
$ python run.py --input_folder ~/Documents/revive-old-photos/input --output ~/Documents/revive-old-photos/output --GPU 0

I get:
Running Stage 1: Overall restoration
python: can't open file 'test.py': [Errno 2] No such file or directory
Finish Stage 1 ...

Running Stage 2: Face Detection
python: can't open file 'detect_all_dlib.py': [Errno 2] No such file or directory
Finish Stage 2 ...

Running Stage 3: Face Enhancement
python: can't open file 'test_face.py': [Errno 2] No such file or directory
Finish Stage 3 ...

Running Stage 4: Blending
python: can't open file 'align_warp_back_multiple_dlib.py': [Errno 2] No such file or directory
Finish Stage 4 ...

All the processing is done. Please check the results.

CUDA error: all CUDA-capable devices are busy or unavailable

when I run code,get the error like thie
"RuntimeError: CUDA error: all CUDA-capable devices are busy or unavailable"

I already installed cuna,nvidia driver,check the processes, this is the info
(venv) dash@dash-KVM:~/Bringing-Old-Photos-Back-to-Life-master$ nvidia-smi
Fri Oct 23 11:07:33 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.118.02 Driver Version: 440.118.02 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GRID T4-8Q On | 00000000:00:09.0 Off | N/A |
| N/A N/A P8 N/A / N/A | 592MiB / 8192MiB | 0% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+

GPU info:
CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GRID T4-8Q"
CUDA Driver Version / Runtime Version 10.2 / 10.2
CUDA Capability Major/Minor version number: 7.5
Total amount of global memory: 8192 MBytes (8589934592 bytes)
(40) Multiprocessors, ( 64) CUDA Cores/MP: 2560 CUDA Cores
GPU Max Clock rate: 1590 MHz (1.59 GHz)
Memory Clock rate: 5001 Mhz
Memory Bus Width: 256-bit
L2 Cache Size: 4194304 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 1024
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 3 copy engine(s)
Run time limit on kernels: No
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 0 / 9
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.2, CUDA Runtime Version = 10.2, NumDevs = 1
Result = PASS

bigger crack on old photo

hi, I tried and unfortunately it can't store my preciously old photo which the scratch is big and across the face, is there any way I could fine-tune the code so it could restore the scratch on face? thanks.

ImportError: DLL load failed: The specified module could not be found.

Hi, thank you for this amazing work.

Unfortunately, I have run into 2 issues while trying to run this on Windows 10 Anaconda Prompt

my input

python run.py --input_folder input --output_folder output --GPU 0 --with_scratch

the error

Running Stage 1: Overall restoration
initializing the dataloader
model weights loaded
directory of testing image: input
Traceback (most recent call last):
  File "detection.py", line 151, in <module>
    main(config)
  File "detection.py", line 85, in main
    imagelist = os.listdir(config.test_path)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'input'
You are using NL + Res
Traceback (most recent call last):
  File "test.py", line 110, in <module>
    input_loader = os.listdir(opt.test_input)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'output\\stage_1_restore_output\\masks\\input'
Finish Stage 1 ...


Running Stage 2: Face Detection
Traceback (most recent call last):
  File "detect_all_dlib.py", line 24, in <module>
    import dlib
  File "E:\Anaconda3\envs\restore\lib\site-packages\dlib\__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: DLL load failed: The specified module could not be found.
Finish Stage 2 ...


Running Stage 3: Face Enhancement
The main GPU is
0
Traceback (most recent call last):
  File "test_face.py", line 15, in <module>
    dataloader = data.create_dataloader(opt)
  File "G:\Bringing-Old-Photos-Back-to-Life\Face_Enhancement\data\__init__.py", line 13, in create_dataloader
    instance.initialize(opt)
  File "G:\Bringing-Old-Photos-Back-to-Life\Face_Enhancement\data\face_dataset.py", line 29, in initialize
    image_list = os.listdir(image_path)
FileNotFoundError: [WinError 3] The system cannot find the path specified: './datasets/cityscapes/output\\stage_2_detection_output'
Finish Stage 3 ...


Running Stage 4: Blending
Traceback (most recent call last):
  File "align_warp_back_multiple_dlib.py", line 23, in <module>
    import dlib
  File "E:\Anaconda3\envs\restore\lib\site-packages\dlib\__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: DLL load failed: The specified module could not be found.
Finish Stage 4 ...


All the processing is done. Please check the results.

The output folder is empty

I already have CUDA 10.2 and cudnn64_7.dll in PATH, but the dlib error still pops up.
And I have no idea how to solve the backslashes issue.

How can I solve this?
Thank you!

Software installation/use tutorial

Could someone insert an installation and use tutorial for Windows 10?
I have installed Python, Anaconda, PyThorc and Nvidia Cuda, but I didn't understand how to install and use this artificial intelligence software for restoring old photos (sorry if my English is bad but I'm Italian and I'm using Google Translate)

Installation command failure

Sorry for this trivial question. I have tried to run every command for installation:

cd Face_Enhancement/models/networks/
git clone https://github.com/vacancy/Synchronized-BatchNorm-PyTorch
cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .

at the step:

cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .
I got the following error:
'cp' is not recognized as an internal or external command, operable program or batch file.

What I have done wrong ?

Blur vs Motion-Blur on Text Image Restoration.

Hello. At first, Thanks for s sharing this amazing project. You guys have done a really good job.

Currently, I'm going through your research paper. As you stated in the paper, the local branch targets the unstructured defects, such as noises and blurriness. This inspired me to try it over an ongoing problem about OCR (here). Just to make a quick test, I've tried it on two cases, gaussian blur and motion blur text (with minimum acute). I've found that the model does a great job of restoring gaussian blurry text but not much on motion blur. Please see the results below, (left-side: normal image; right-side: restored image)

two_soft

I believe that the model has much potential to restored more complex degraded raw samples. However, I like to know, in training time, was it ensured various blurring effects in the training data set? Or, to generalize the model on various blurry effects, do we need to fine-tune it?

Colab "Try it on your own photos!" fails to save output

When running the section "Try it on your own photos!" the upload of the photo works fine:

EMILIA 78.png(image/png) - 6794251 bytes, last modified: 19/9/2020 - 100% done
Saving EMILIA 78.png to EMILIA 78.png

and even the pipeline seems to work:

Running Stage 1: Overall restoration
Now you are processing EMILIA 78.png
Skip EMILIA 78.png
Finish Stage 1 ...


Running Stage 2: Face Detection
Finish Stage 2 ...


Running Stage 3: Face Enhancement
The main GPU is 
0
dataset [FaceTestDataset] of size 0 was created
The size of the latent vector size is [8,8]
Network [SPADEGenerator] was created. Total number of parameters: 92.1 million. To see the architecture, do print(network).
hi :)
Finish Stage 3 ...


Running Stage 4: Blending
Finish Stage 4 ...


All the processing is done. Please check the results.

but there is any file named "EMILIA 78.png(As the input) in the output folder, so the next section "Visualize" will do nothing, since the folderoutput/` has only the test images, but not this one, I assume due to the following like:

Skip EMILIA 78.png

so it seems it is related to #3

So I manually rescaled:

EMILIA 78.png(image/png) - 1639881 bytes, last modified: 19/9/2020 - 100% done
Saving EMILIA 78.png to EMILIA 78.png

Closing here then, forwarding a question in the other issue.

ImportError: No module named torch.autograd

Hello all!, It seems install is ok

Requirement already satisfied: torchvision in /usr/local/lib/python3.8/dist-packages (0.8.1) Requirement already satisfied: torch==1.7.0 in /usr/local/lib/python3.8/dist-packages (from torchvision) (1.7.0) Requirement already satisfied: pillow>=4.1.1 in /usr/lib/python3/dist-packages (from torchvision) (7.2.0) Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from torchvision) (1.19.2) Requirement already satisfied: future in /usr/lib/python3/dist-packages (from torch==1.7.0->torchvision) (0.18.2) Requirement already satisfied: typing-extensions in /usr/lib/python3/dist-packages (from torch==1.7.0->torchvision) (3.7.4.3) Requirement already satisfied: dataclasses in /usr/local/lib/python3.8/dist-packages (from torch==1.7.0->torchvision) (0.6)
Guided by Installation instructions all ok except when I launch:
# python run.py --input_folder /imgs/ --output_folder /imgs/output/ --GPU 0

Running Stage 1: Overall restoration Traceback (most recent call last): File "test.py", line 6, in <module> from torch.autograd import Variable ImportError: No module named torch.autograd Traceback (most recent call last): File "run.py", line 91, in <module> for x in os.listdir(stage_1_results): OSError: [Errno 2] No such file or directory: '/imgs/output/stage_1_restore_output/restored_image'

root@DESKTOP-H0VF09L:/home/akenateb/Bringing-Old-Photos-Back-to-Life# python Python 2.7.18 (default, Apr 20 2020, 20:30:41) [GCC 9.3.0] on linux2
`
What I am doing wrong?
Thanks in advance.

Make code python3 friendly

RIght now, because of hardcoded paths with usage of python command there is no possibility to make full run with python3

cuda requirement

Is it possible to run this on a (recent) Mac, which does not support CUDA? I would have guessed setting --GPU 0 would not attempt to call CUDA, but it fails.

File "/Users/../Desktop/bopbtl/venv/lib/python3.7/site-packages/torch/cuda/__init__.py", line 61, in _check_driver
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

Absolute path not found

I setup everything successfully using pip3 and I run this with a test image in the test_image folder on my desktop.

python run.py --input_folder /Users/g14a/Desktop/test_image/ --output_folder /Users/g14a/Desktop/test_output/ --GPU 0 --with_scratch

and then I get this error log.

Running Stage 1: Overall restoration
Traceback (most recent call last):
  File "detection.py", line 9, in <module>
    import torch
ImportError: No module named torch
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    from torch.autograd import Variable
ImportError: No module named torch.autograd
Traceback (most recent call last):
  File "run.py", line 79, in <module>
    for x in os.listdir(stage_1_results):
OSError: [Errno 2] No such file or directory: '/Users/g14a/Desktop/test_output/stage_1_restore_output/restored_image'

Is there anything I'm missing here?

No such file or directory: output/stage_1_restore_output/restored_image

Need to manually create the restored_image dir otherwise the following failure occurs:

$ python run.py --input_folder ~/Documents/revive-old-photos/input --output ~/Documents/revive-old-photos/output --GPU 0
Running Stage 1: Overall restoration
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    from torch.autograd import Variable
ImportError: No module named torch.autograd
Traceback (most recent call last):
  File "run.py", line 79, in <module>
    for x in os.listdir(stage_1_results):
FileNotFoundError: [Errno 2] No such file or directory: '~/Documents/revive-old-photos/output/stage_1_restore_output/restored_image'

Face_Enhancement usage guide

How can I run Face Enhancement on a custom image?

I tried this command:

cd Face_Enhancement
python -m test_face --dataroot ./datasets/faces/ --netG pix2pixhd --gpu_ids 0

but the results are all-gray images.

RuntimeError: CUDA out of memory.

I get the following error:
RuntimeError: CUDA out of memory. Tried to allocate 88.00 MiB (GPU 0; 5.80 GiB total capacity; 4.14 GiB already allocated; 154.56 MiB free; 4.24 GiB reserved in total by PyTorch)

Is there a way to allocate more memory? I do not get why 4.14Gb are already allocated.

how about the performance ?

I have get the excellent result with my uploaded img in Colab

  1. can you give some performance test result?
    such as how many fps in 1080Ti or some other GPU

  2. can you give some slim or optimize suggestion to speedup inference

thanks a lot

face enhance model load failed

thanks for the fantastic works!
I was testing the face enhance model with my own dataset which struct as follows:
dataset
-- xyz
-- test_A (image to be enhanced, 256*256, .png format)
-- test_B (empty as no labels were provided)

When I run test_face.py I got the following errors:
RuntimeError: Error(s) in loading state_dict for SPADEGenerator:
size mismatch for fc.weight : copying a param with shape torch.Size([1024,3,3,3]) from checkpoint, the shape in current model is torch.Size([1024,184,3,3]).
similar errors for some other weights i.e., head_0_norm_0.mlp_shared.0.weight

love to hear from u guys
cheers

CUDA out of memory

With some image throws this exception:
Skip a.png due to an error:
CUDA out of memory. Tried to allocate 3.10 GiB (GPU 0; 8.00 GiB total capacity; 3.83 GiB already allocated; 2.17 GiB free; 4.40 GiB reserved in total by PyTorch).

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.