Code Monkey home page Code Monkey logo

skyar's Introduction

SkyAR

Preprint | Project Page | Google Colab

Official Pytorch implementation of the preprint paper "Castle in the Sky: Dynamic Sky Replacement and Harmonization in Videos", in arXiv:2010.11800.

We propose a vision-based method for video sky replacement and harmonization, that can automatically generate realistic and dramatic sky backgrounds in videos with controllable styles. Different from previous sky editing methods that either focus on static photos or require inertial measurement units integrated in smartphones on shooting videos, our method is purely vision-based, without any requirements on the capturing devices, and can be well applied to either online or offline processing scenarios. Our method runs in real-time and is free of user interactions. We decompose this artistic creation process into a couple of proxy tasks including sky matting, motion estimation, and image blending. Experiments are conducted on videos diversely captured in the wild by handheld smartphones and dash cameras, and show high fidelity and good generalization of our method in both visual quality and lighting/motion dynamics.

In this repository, we implement the complete training/testing pipeline of our paper based on Pytorch and provide several demo videos that can be used for reproduce the results reported in our paper. With the code, you can also try on your own data by following the instructions below.

Our code is partially adapted from the project pytorch-CycleGAN-and-pix2pix, and the project Python-Video-Stab.

License

Creative Commons License  SkyAR by Zhengxia Zou is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

One-min video result

IMAGE ALT TEXT HERE

Requirements

See Requirements.txt.

Setup

  1. Clone this repo:
git clone https://github.com/jiupinjia/SkyAR.git 
cd SkyAR
  1. Download the pretrained sky matting model from Google Drive, and unzip into the repo directory.
unzip checkpoints_G_coord_resnet50.zip

To produce our results

District 9 Ship (video source)

python skymagic.py --path ./config/config-canyon-district9ship.json

Super-moon on Ann Arbor

python skymagic.py --path ./config/config-annarbor-supermoon.json

Config your settings

If you want to try on your own data, or want a different blending style, you can config the .json files in the ./config directory. The following we give a simple example of how the parameters are defined.

{
  "net_G": "coord_resnet50",
  "ckptdir": "./checkpoints_G_coord_resnet50",

  "input_mode": "video",
  "datadir": "./test_videos/annarbor.mp4",
  "skybox": "floatingcastle.jpg",

  "in_size_w": 384,
  "in_size_h": 384,
  "out_size_w": 845,
  "out_size_h": 480,

  "skybox_center_crop": 0.5,
  "auto_light_matching": false,
  "relighting_factor": 0.8,
  "recoloring_factor": 0.5,
  "halo_effect": true,

  "output_dir": "./eval_output",
  "save_jpgs": false
}

Google Colab

Here we also provide a minimal working example of the inference runtime of our method. Check out Open In Colab and see your result on Colab.

To retrain your sky matting model

Please note that if you want to train your own model, you need to download the complete CVPRW20-SkyOpt dataset. We only uploaded a very small part of it due to the limited space of the repository. The mini-dataset we included in this repository is only used as an example to show how the structure of the file directory is organized.

unzip datasets.zip
python train.py \
	--dataset cvprw2020-ade20K-defg \
	--checkpoint_dir checkpoints \
	--vis_dir val_out \
	--in_size 384 \
	--max_num_epochs 200 \
	--lr 1e-4 \
	--batch_size 8 \
	--net_G coord_resnet50

Limitations

The limitation of our method is twofold. First, since our sky matting network is only trained on daytime images, our method may fail to detect the sky regions on nighttime videos. Second, when there are no sky pixels during a certain period of time in a video, or there are no textures in the sky, the motion of the sky background cannot be accurately modeled.

The figure below shows two failure cases of our method. The top row shows an input frame from BDD100K at nighttime (left) and the blending result (middle) produced by wrongly detected sky regions (right). The second row shows an input frame (left, video source), and the incorrect movement synchronization results between foreground and rendered background (middle and right).

Citation

If you use this code for your research, please cite our paper:

@inproceedings{zou2020skyar,
    title={Castle in the Sky: Dynamic Sky Replacement and Harmonization in Videos},
    author={Zhengxia Zou},
    year={2020},
    journal={arXiv preprint arXiv:2010.11800},
}

skyar's People

Contributors

akiyamasho avatar amrzv avatar jiupinjia avatar lukewood 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

skyar's Issues

Input Error

I have a problem while runniing the project. there is a ./torch folder under my c drive.but my other programs are under F,i dont know if it has anything with it. :(

QQ截图20201125130131

tile_skybox_img in skyboxengine.py

Hello!

First of all, great work!
I was wondering if you can explain a little bit the meaning of concat for imgtile and how it works.

Thank you!

Skybox follows the camera

Hi. First, thanks for providing this in github for us to experiment.

I've tried to use a custom video, but it seems like the skybox is always following the camera.

This is an example:
https://youtu.be/Ogt2GM-H2LU

And this is my json file:

{
  "net_G": "coord_resnet50",
  "ckptdir": "./checkpoints_G_coord_resnet50",

  "input_mode": "video",
  "datadir": "./test_videos/test.mp4",
  "skybox": "district9ship.jpg",

  "in_size_w": 384,
  "in_size_h": 384,
  "out_size_w": 1280,
  "out_size_h": 720,

  "skybox_center_crop": 0.6,
  "auto_light_matching": false,
  "relighting_factor": 0.9,
  "recoloring_factor": 1.0,
  "halo_effect": true,

  "output_dir": "./jpg_output",
  "save_jpgs": true
}

The file is 1280x720.

Any idea why this happens?

Regards.

Cloudy Footage

I can see a real use case for this is my realestate videography to replace the cloudy sky of an overcast day to a sunny sky, however after testing with some cloudy footage in google collab it seems like it doesn't work with overcast skies. It just fails to process most of the frames. Or am i doing something wrong?

how to save the videos

After processing the image and videos, there is no mp4 in the "jpg_output".
So , how to save the result.
please

ImportError: cannot import name 'compare_ssim' from 'skimage.measure'. I need help as I cannot start train.py

Hello, I am having trouble running train.py

(base) [contrast@cosmos SkyAR-main]$ python train.py \

--dataset cvprw2020-ade20K-defg
--checkpoint_dir checkpoints
--vis_dir val_out
--in_size 384
--max_num_epochs 200
--lr 1e-4
--batch_size 8
--net_G coord_resnet50
Traceback (most recent call last):
File "train.py", line 4, in
import utils
File "/home/contrast/Desktop/SkyAR-main/utils.py", line 4, in
from skimage.measure import compare_ssim as sk_cpt_ssim
ImportError: cannot import name 'compare_ssim' from 'skimage.measure' (/home/contrast/Applications/mc/lib/python3.8/site-packages/skimage/measure/init.py)
(base) [contrast@cosmos SkyAR-main]$

Question regarding CoordConv

Hello,

First of all, nice job. I was wondering why did you only encode the y coordinate for the CoordConv instead of both x, y or only x. Can you explain the reason behind this?

Thank you!

Noncommercial

Hey! Great library!
I'm concerned about the noncommercial limitation.
I want you to consider changing this and here's why:

  1. It only limits the project and where people can go with it.
    • It means the project can't be included in a commercial work,
      no matter how greatly that commercial work may add to it.
    • It's not what's keeping your code free, as your code is here on github for everybody to see.
  2. It only complicates things when people use your code.
    • Someone may include it in a GPL-licensed repo
      and then someone may use that GPL-licensed repo commercially,
      like how linux distros can come with a system,
      and even if they release the entire system for people to see,
      they are still using it commercially by selling a system with it on it.
      This could lead to accidental misuse of your code under this license.
  3. Maybe a different license wouldn't be so bad. :)
    • It seems like you would actually prefer the GPL license.
      it's what Linux uses and everyone all knows that Linux is pretty much the mother of all free software.
    • Or you could consider:
      Apache 2.0,
      MPL,
      etc
    • If you want it to be truly free, why not just
      MIT,
      CC0,
      The Unlicense,
      etc, etc.
      There are plenty of great licensing options that don't restrict the software to this extent.
      I think you would find that more people would be willing to use this software,
      even noncommercially, if you changed this. :)

Thank you SO MUCH for creating this software and for considering this request.
I appreciate it greatly! 👍

Can't install Requirements.txt

Hello! I have a problem with installing Requirements.txt. I can't correctly install modules and every time gets an error.

  • scipy send No lapack/blas resources found. and other libraries. Can you send a list of all commands for pretty installing?
    To install all modules I'm using pip install Requirements.txt.

import error

from skimage.measure import compare_ssim as sk_cpt_ssim in utils.py
import problems: ImportError: cannot import name 'compare_ssim' from 'skimage.measure' (D:\anaconda\envs\pytorch\lib\site-packages\skimage\measure_init_.py)
I find that the latest version of scikit-image doesn't have "compare_ssim".
Maybe an update in requirements.txt is needed

I make a simply implementation, and have a small question.

Awesome work. I like this project very much. So I am implementing this project on another deep learning framework (paddlepaddle) to make it easier to use. Now the Demo has been Done. Online trying link emm, this page is written in Chinese. The github code will be release soon.

And I have a small question that can I upload my implementation to paddlehub (a open source pre-training model management tool similar to the Pytorch Hub)? I want more people to simply use this awesome project.

Need to do on Images only

Hello, can you suggest where in the code I can make changes to work on images only instead of videos?

I can only generate the 40frame GIF previews in Colab

Running through the Google Colab notebook, Wandb only seems to contain GIF outputs for my videos. The notebook says I can download a full video rather than the preview at /SkyAR/demo.avi but I see no AVI files in my Wandb media. What am I missing here?

Great library

Bro, I've been playing with your library all evening!
Amazing work! Made my friends worry that I am on another planet)))
I wrote a small tutorial if anyone is interested.

Shure, this work is a good case when there is something to show in a code presentation in contrast with a usual boring code description.

colab

can you please add a google colab for inference thanks

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.