Giter Site home page Giter Site logo

roysheffer / im2wav Goto Github PK

View Code? Open in Web Editor NEW
98.0 3.0 9.0 24.3 MB

Official implementation of the pipeline presented in I hear your true colors: Image Guided Audio Generation

License: MIT License

Python 100.00%
audio machine-learning pytorch audio-generation image-to-audio video-to-audio

im2wav's Introduction

I Hear Your True Colors: Image Guided Audio Generation

This repo contains the official PyTorch implementation of the pipeline presented in I Hear Your True Colors: Image Guided Audio Generation: Paper, Project page.

Abstract

We propose Im2Wav, an image guided open-domain audio generation system. Given an input image or a sequence of images, Im2Wav generates a semantically relevant sound. Im2Wav is based on two Transformer language models, that operate over a hierarchical discrete audio representation obtained from a VQ-VAE based model. We first produce a low-level audio representation using a language model. Then, we upsample the audio tokens using an additional language model to generate a high-fidelity audio sample. We use the rich semantics of a pre-trained CLIP embedding as a visual representation to condition the language model. In addition, to steer the generation process towards the conditioning image, we apply the classifier-free guidance method. Results suggest that Im2Wav significantly outperforms the evaluated baselines in both fidelity and relevance evaluation metrics. Additionally, we provide an ablation study to better assess the impact of each of the method components on overall performance. Lastly, to better evaluate image-to-audio models, we propose an out-of-domain image dataset, denoted as ImageHear. ImageHear can be used as a benchmark for evaluating future image-to-audio models.


Pipeline overview

Installation

git clone [email protected]:RoySheffer/im2wav.git
cd im2wav
pip install -r requirements.txt

Note: torch installation may depend on your cuda version. see Install torch

Usage

We provide a toy example using two videos and two single images. The same scripts can be used for the full VGGSound or any other custom dataset. We additionally include the ImageHear dataset under Data/ImageHear/ folder.

We start by setting the directory where all scripts should be run from:

mkdir run && cd run

Next, we collect the CLIP image representations:

Collect CLIP representations of video directory

python ../Data/preprocess/collect_video_CLIP.py \
-videos_dir ../Data/examples/video

Collect CLIP representations of images

python ../Data/preprocess/collect_image_CLIP.py \
-path_list ../Data/ImageHear/bongo1.jpg  ../Data/ImageHear/dog1.jpg

Train

Train the models:

  • Set a batch size (bs) according to your GPU size.

Train VQ-VAE

python ../models/train.py \
--hps=small_multi_level_vqvae \
--name=im2wav_vq \
--sample_length=65536 \
--bs=2 \
--audio_files_dir=../Data/examples/wav \
--labels=False \
--train \
--aug_shift \
--aug_blend \

Train Low model

python ../models/train.py \
--hps=small_multi_level_vqvae,small_labelled_prior,all_fp16,cpu_ema \
--name=im2wav_low \
--sample_length=65536 \
--n_ctx=2048 \
--bs=2 \
--aug_shift \
--aug_blend \
--audio_files_dir=../Data/examples/wav \
--labels=True \
--train \
--test \
--prior \
--restore_vqvae=logs/im2wav_vq/checkpoint_latest.pth.tar \
--levels=2 \
--level=1 \
--weight_decay=0.01 \
--save_iters=2 \
--file2CLIP=video_CLIP \
--clip_emb  \
--video_clip_emb \
--class_free_guidance_prob=0.5

Train Up model

python ../models/train.py \
--hps=small_multi_level_vqvae,small_upsampler,all_fp16,cpu_ema \
--name=im2wav_up \
--sample_length=65536 \
--n_ctx=8192 \
--bs=2 \
--audio_files_dir=../Data/examples/wav \
--labels=True \
--train \
--test \
--aug_shift \
--aug_blend \
--save_iters=2 \
--prior \
--restore_vqvae=logs/im2wav_vq/checkpoint_latest.pth.tar \
--file2CLIP=video_CLIP \
--levels=2 \
--level=0 \
--clip_emb

Sample

After the models converge, we can use the trained models for an audio generation as follows:

Video condition sampling

python ../models/sample.py \
-bs 2 \
-experiment_name video_CLIP \
-CLIP_dir video_CLIP \
-models my_model

Image condition sampling

python ../models/sample.py \
-bs 2 \
-wav_per_object 2 \
-experiment_name image_CLIP \
-CLIP_dict image_CLIP/CLIP.pickle \
-models my_model

Use pre-trained model

We start by setting the directory where the pre-trained model weights should be downloaded to:

mkdir ../pre_trained

Download the pre-trained model weights

pip install gdown

gdown 1lCrGsMXqmeKBk-3B3J2jzxNur9olWseb -O ../pre_trained/
gdown 1v9dmCwrEwkwJhbe2YF3ScM2gjVplSLzt -O ../pre_trained/
gdown 1UyNBjoxgqBYqA_aYhOu6BHYlkT4CD_M_ -O ../pre_trained/

Sampling from pre-trained model

Repeat the Video/Image condition sampling steps replacing my_model with im2wav.

Cite

If you find this implementation useful please consider citing our work:

@misc{sheffer2022i,
    title={I Hear Your True Colors: Image Guided Audio Generation},
    author={Roy Sheffer and Yossi Adi},
    year={2022},
    eprint={2211.03089},
    archivePrefix={arXiv},
    primaryClass={cs.SD}
}

License

This repository is released under the MIT license as found in the LICENSE file. Some of the code in models dir was adapted from the JukeBox repository.

im2wav's People

Contributors

roysheffer 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

Watchers

 avatar  avatar  avatar

im2wav's Issues

generated sound is noise

The sound obtained by following the steps in readme and using the pre trained model is noise. May I ask what is the reason for this?

Video Data Preprocessing

Hi Roy,

I am collecting the CLIP representation of VGGSound videos by running the collect_video_CLIP.py file. I had to change some codes for some reason, and now it takes a long time to calculate all the videos. I'm wondering how long will it take to collect all the CLIP features for videos in the VGGSound dataset through the original collect_video_CLIP.py ?

BTW, I just changed the way loading clip model for my server is offline.

Evaluation code

Hi Roy! Are you planning to release the code of how to compute those metrics reported in your paper (FAD, KL, CS, ACC)? Thanks!

Can sample length be changed for a pretrained model?

parser.add_argument("-sample_length", dest='sample_length', action='store', type=int, default=65536)

I found the sample length argument in models/sample.py, but change it does not change the generated audio length.
Is there any way to change the generated audio length for a pretrained model?
It seems that sample_length depends on self.sample_length = self.n_ctx*self.raw_to_tokens and cannot be changed.

GPU configuration

Hi Roy,

Thanks for your interesting work! I was wondering how many GPUs are required at least to perform the training (bs=2)?

The loss does't decrease

I use your model to train VQVAE, but it seems the loss does't decrease. Are there something that I need to change?

Issues when sampling from pre-trained model

Hi, thx for your great work! But I have some issues when I try to sample from the pre-trained model
Errors are the following:
No such file or directory: 'logs/im2wav_vq/checkpoint_latest.pth.tar'
and
UnboundLocalError: local variable 'upsampler' referenced before assignment.

I try to sample with images and already gdown the pretrained model and collect CLIP representations

Unable to get ACC result reported in the paper

Hi Roy!
For the pretrained im2wav model, I can reproduce most of the metrics reported in your paper. However, when I use pretrained PaSST to compute the accuracy over 30 ImageHear classes for 15,446 VGGSound test set, I only get 23.6% for the reference audio and 13.4% for the generated audio by the pretrained im2wav model you provide. I've only got 2800 samples from VGGSound-test that belong to ImageHear class following the mapping provided here.

The pretrained PaSST is specified as get_model_passt(arch="passt_s_swa_p16_128_ap476", n_classes=527, s_patchout_t=40, s_patchout_f=4) following their repo.

Is it possible for you to share your code of computing ACC? Thanks!

"skvideo.io.vread" reports error

Hi Roy,

Thank you for your prompt reply! I really appreciate that you always respond quickly.

I'm collecting CLIP representation of VGGSound videos by running the collect_video_CLIP.py following your instruction. However, for video l6q7shFb8zs_000041 and EktPRpYX9KI_000038, it reports this error:

Traceback (most recent call last):
  File "/home/anaconda3/envs/myenv/lib/python3.8/site-packages/skvideo/io/ffmpeg.py", line 271, in _read_frame_data
    assert len(arr) == framesize
AssertionError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "debug.py", line 194, in <module>
    check_corrupted_video()
  File "debug.py", line 173, in check_corrupted_video
    videodata = skvideo.io.vread(video)
  File "/home/anaconda3/envs/myenv/lib/python3.8/site-packages/skvideo/io/io.py", line 148, in vread
    for idx, frame in enumerate(reader.nextFrame()):
  File "/home/anaconda3/envs/myenv/lib/python3.8/site-packages/skvideo/io/ffmpeg.py", line 297, in nextFrame
    yield self._readFrame()
  File "/home/anaconda3/envs/myenv/lib/python3.8/site-packages/skvideo/io/ffmpeg.py", line 281, in _readFrame
    s = self._read_frame_data()
  File "/home/anaconda3/envs/myenv/lib/python3.8/site-packages/skvideo/io/ffmpeg.py", line 275, in _read_frame_data
    raise RuntimeError("%s" % (err1,))
RuntimeError

I was wondering if this happens to you as well? I obtain 199,176 videos from the VGGSound dataset and only these two cannot be processed.

train/test split

Hi,

I was wondering in your experiments did you use the exact same train/test split as specified in VGGSound's csv file or did you simply just use a train_test_split ratio to divide the whole dataset. Because when I checked the code, I saw you did the split here using the ratio. But in the paper, you mentioned that "We follow the original VGGSound train/test splits." Please correct me if I was wrong. Thank you!

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.