Giter Site home page Giter Site logo

sinfusion-code's Introduction

[ICML 2023] SinFusion - Training Diffusion Models on a Single Image or Video

project arxiv Conference

Official PyTorch implementation of "SinFusion - Training Diffusion Models on a Single Image or Video".

Data and Checkpoints

You can find training images, training video frames, and some sample checkpoints in the Dropbox Folder.

You can download the training images and video frames from the images folder into a local ./images folder.

Note that a video is represented as a directory with PNG files in the format <frame number>.png, and should be placed within the ./images/video folder. For example:

some/path/sinfusion/images/video/my_video/
   1.png
   2.png
   3.png
   ...

To download the checkpoints, download the checkpoints/lightning_logs directory from the Dropbox to a local ./lightning_logs directory. The structure should be, for example -

some/path/sinfusion/lightning_logs/
    balloons.png/
        image_balloons_sample_weights/checkpoints/last.ckpt
    tornado/
        video_tornado_sample_weights_predictor/checkpoints/last.ckpt
        video_tornado_sample_weights_projector/checkpoints/last.ckpt

Following this you can directly sample the trained weights (using the default configuration in config.py) with the generation command lines below (notice you need to use the relevant run_name, for example - image_balloons_sample_weights or video_tornado_sample_weights).

Training

Training a single-image DDPM:

python main.py --task='image' --image_name='balloons.png' --run_name='train_balloons_0'

Training a single-video DDPM (Predictor and Projector) for generation and extrapolation:

python main.py --task='video' --image_name='tornado' --run_name='tornado_video_model_0'

Training a single-video DDPM (Interpolator and Projector) for temporal upsampling:

python main.py --task='video_interp' --image_name='hula_hoop'  --run_name='hula_hoop_interpolate_0'

To choose the image/video, place the image/video in the data folder (see Data) and replace the image_name argument with the name of the image/video.

Also, notice the run_name argument. This is the name of the experiment, and will be used in the generation to load the model. If this argument isn't specified, a default name will be used.

You may also change any configuration parameter via the command line. For a full list of configuration options, please see config.py.

Async Training

To run the training script asynchronously, you can run a line similar to the following -

PYTHONUNBUFFERED=1 nohup python main.py --task='video' --image_name='tornado' --run_name='tornado_video_model_0' > tornado_video_model_0.out &

Generation

Most arguments are the same for the generation process as the training process. Notice that the run_name argument should be the same as the one used in the training cmdline.

To generate a diverse set of images from a single-image DDPM:

python sample.py --task='image' --image_name='balloons.png' --run_name='train_balloons_0' [--sample_count=8] [--sample_size='(H, W)']

To generate a diverse video from a single-video DDPM:

python sample.py --task='video' --image_name='tornado' --output_video_len=100 --run_name=tornado_video_0

To extrapolate a video from a given frame using a single-video DDPM:

python sample.py --task='video' --image_name=tornado --output_video_len=100 --start_frame_index=33 --run_name=tornado_video_0

To temporally upsample a video by a specific factor (x2, x4, ...) -

python sample.py --task='video_interp' --image_name=hula_hoop --interpolation_rate=4 --run_name=hula_hoop_interpolate_0

By default (if output_dir isn't specified, the generated images/videos will be saved in the ./outputs folder.

Citation

If you find our project useful for your work please cite:

@inproceedings{nikankin2022sinfusion,
  title={SinFusion: Training Diffusion Models on a Single Image or Video},
  author={Nikankin, Yaniv and Haim, Niv and Irani, Michal},
  booktitle={International Conference on Machine Learning},
  organization={PMLR},
  year={2023}
}

sinfusion-code's People

Contributors

yanivnik avatar

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.