Git Product home page Git Product logo

shadow-removal-via-generative-priors's Introduction

ShadowGP

This repository provides the official codes for our paper: Unsupervised Portrait Shadow Removal via Generative Priors (ACM MM 2021).

Unsupervised Portrait Shadow Removal via Generative Priors
Yingqing He*, Yazhou Xing*, Tianjia Zhang, Qifeng Chen (* indicates joint first authors)
HKUST

In this repository, we propose an unsupervised method for portrait shadow removal, named as ShadowGP. ShadowGP can recover a shadow-free portrait image via single image optimization, without a large paired training dataset, which is expensive to collect and time-consuming to train. Besides, our method can also be extended to facial tattoo removal and watermark removal tasks.

ShadowGP can decompose the single input shadowed portrait image into 3 parts: a full-shadow portrait, a shadow-free portrait and a shadow mask. Blending the three parts together can reconstruct the input shadowed portrait. The decomposed shadow-free portrait is the target output.


Install Environment

To install and activate the environment, run the following commands:

conda create -n shadowgp python=3.7
conda activate shadowgp
pip3 install torch==1.3.1+cu100 torchvision==0.4.2+cu100 -f https://download.pytorch.org/whl/torch_stable.html
pip3 install opencv-python tqdm scikit-image==0.15 Pillow==7.1.0 Ipython ninja

Our code has the same system requirements as StyleGAN2-PyTorch.


Download Checkpoints

Download the pretrained StyleGAN 550000.pt and the pretrained face segmentation model face-seg-BiSeNet-79999_iter.pth from the google drive, and put them in checkpoint/.

cd Shadow-Removal-via-Generative-Priors
mkdir checkpoint
mv ${YOUR_PATH}/550000.pt checkpoint/
mv ${YOUR_PATH}/face-seg-BiSeNet-79999_iter.pth checkpoint/

Optional: If the lpips checkpoint cannot be downloaded automatically, you can also manually download the weights.tar.gz to the project directory and run tar -zxvf weights.tar.gz. Then you will see the checkpoint in lpips/weights/v0.1/vgg.pth.

Run

bash run.sh

Then it will create a results folder including all the intermidiate results and the final output results in results/res.

Acknowledgement

Our code is built on StyleGAN2-PyTorch.


Citation

@inproceedings{he21unsupervised,
  title     = {Unsupervised Portrait Shadow Removal via Generative Priors},
  author    = {He, Yingqing and Xing, Yazhou and Zhang, Tianjia and Chen, Qifeng},
  booktitle = {ACM International Conference on Multimedia (ACM MM)},
  year      = {2021}
}

shadow-removal-via-generative-priors's People

Contributors

yingqinghe avatar yzxing87 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shadow-removal-via-generative-priors's Issues

How to find (shadow) relevant features in the latent space?

Hello, I'm currently trying to implement the first step of your proposed algorithm (input: portrait image, face mask, output: shadow free image). I successfully created the face mask with the Bisenet and removed the background from the portrait image. In the next step I received the latent vectors from StyleGAN.

My question now is: How do you explore the latent space to find the relevant parts of the vector which control the shadows? You create K random latent vectors but what is your strategy? How many values do you manipulate in every sample? Any hint would be very helpful to me! Thanks in advance.

No such file or directory: lpips/weights/v0.1/vgg.pth

Hi there, ML noob here.

I am trying to run the code in this repository on Google Colab. I have downloaded the two checkpoints provided in your drive and installed all necessary libraries.

Unfortunately, when I run bash run.sh I receive the following error message:

target img path: imgs/9165-006-input.png
Downloading: "https://download.pytorch.org/models/resnet18-5c106cde.pth" to /root/.cache/torch/hub/checkpoints/resnet18-5c106cde.pth
100% 44.7M/44.7M [00:00<00:00, 99.4MB/s]
Setting up Perceptual loss...
Downloading: "https://download.pytorch.org/models/vgg16-397923af.pth" to /root/.cache/torch/hub/checkpoints/vgg16-397923af.pth
100% 528M/528M [00:04<00:00, 132MB/s] 
Loading model from: /content/drive/MyDrive/Shadow-Removal-via-Generative-Priors/lpips/weights/v0.1/vgg.pth
Traceback (most recent call last):
  File "remove_shadow.py", line 379, in <module>
    main(img_path, res_dir, args.device, args)
  File "remove_shadow.py", line 166, in main
    model="net-lin", net="vgg", use_gpu=device.startswith("cuda")
  File "/content/drive/MyDrive/Shadow-Removal-via-Generative-Priors/lpips/__init__.py", line 22, in __init__
    self.model.initialize(model=model, net=net, use_gpu=use_gpu, colorspace=colorspace, spatial=self.spatial, gpu_ids=gpu_ids)
  File "/content/drive/MyDrive/Shadow-Removal-via-Generative-Priors/lpips/dist_model.py", line 73, in initialize
    self.net.load_state_dict(torch.load(model_path, **kw), strict=False)
  File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 699, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 231, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 212, in __init__
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Shadow-Removal-via-Generative-Priors/lpips/weights/v0.1/vgg.pth'

The error is thrown in line 73 of lpips/dist_model.py. The code I ran does download a vgg16 checkpoint file called vgg16-397923af.pth, so I tried hardcoding the path to this file into line 69 of lpips/dist_model.py. No error is thrown after hardcoding this path, but the output of the network after doing so is very strange:
Screen Shot 2022-06-23 at 4 30 29 PM

This presumably means that hardcoding vgg16-397923af.pth into line 73 was incorrect, especially since in your paper, you use a VGG-19 network.

Should I expect the path lpips/weights/v0.1/vgg.pth to exist after I've run bash run.sh? Was I supposed to include it before hand and if so, where do I download it from?

Thanks!

Dissimilar results. Ideas on approach?

Hello Yingqing, Nice work.

We tested the project and had a few questions.

After passing an input image with similar shadowing as your test cases, we could not achieve the same results. Currently, we change the iterations to double but noticed the shadow map has no variation above the 1st 5 or so. Are there any settings that iterate through more permutations of shadow masks?

About Datasets.

Thanks for sharing your code! And could you please release the datasets of tattoo and watermark removal?

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.