TempoTokens

其他资源 2025-08-15

通过文本到视频模型适应的多元化和对齐的音频到视频生成

该仓库包含通过文本到视频模型改编的官方Pytorch实施多样化和对齐的音频到视频的生成

音频到video.mp4

抽象的

我们考虑的任务是生成以各种语义类别的自然音频样本为指导的多样化和现实视频的任务。对于此任务,视频必须在全球和时间上与输入音频对齐:在全球范围内,输入音频与整个输出视频的语义相关联,并且在时间上,输入音频的每个段都与该视频的相应段相关联。我们利用现有的文本条件视频生成模型和预训练的音频编码器模型。所提出的方法基于轻型适配器网络,该网络学会将基于音频的表示形式映射到文本对视频生成模型期望的输入表示形式。因此,它还可以在文本,音频以及在文本和音频上首次确定的视频生成。我们在三个数据集上广泛验证我们的方法,这些数据集证明了音频视频样本的显着语义多样性,并进一步提出了一种新型的评估度量(AV-Align),以评估生成的视频与输入音频样本的对齐。 AV-ALIGN基于两种方式中能量峰的检测和比较。与最近的最新方法相比,我们的方法生成的视频与内容和时间轴相对于输入声音更好。我们还表明,通过我们的方法制作的视频具有更高的视觉质量,并且更加多样化。

安装

TempoTokens.git cd TempoTokens pip install -r requirements.txt">
git clone git@github.com:guyyariv/ TempoTokens .git
cd TempoTokens
pip install -r requirements.txt

并用以下方式初始化加速环境

accelerate config

下载节拍预训练的模型

mkdir -p models/BEATs/ && wget -P models/BEATs/ -O "models/BEATs/BEATs_iter3_plus_AS2M_finetuned_on_AS2M_cpt2.pt" "https://valle.bl*o*b.core.win*dows.net/share/BEATs/BEATs_iter3_plus_AS2M_finetuned_on_AS2M_cpt2.pt?sv=2020-08-04&st=2023-03-01T07%3A51%3A05Z&se=2033-03-02T07%3A51%3A00Z&sr=c&sp=rl&sig=QJXmSJG9DbMKf48UDIU1MfzIro8HQOf3sqlNXiflY1I%3D"

训练

为我们培训的每个数据集执行相关命令,包括VGGSOUND,Landscape和Audioset-Drum。

accelerate launch train.py --config configs/v2/vggsound.yaml
accelerate launch train.py --config configs/v2/landscape.yaml
accelerate launch train.py --config configs/v2/audioset_drum.yaml

我们强烈建议您根据您的首选项来查看配置文件并自定义参数。

预训练的重量

获取通过访问以下链接进行培训的三个数据集的预训练的权重:https://drive.google.com/drive/folders/10prwoq0m5torvmxilmiqd7j9flpeehts,我们建议您将文件仪保存在名为“模型”的目录中。”

推理

the pypy脚本的目的是使用训练有素的检查点生成视频。使用提供的命令完成模型培训后(或选择了我们的预训练型号),您就可以轻松地从我们用于培训的数据集中创建视频,例如Vggsound,Landscape和Audioset-Drum。

accelerate launch inference.py --mapper_weights models/vggsound/learned_embeds.pth --testset vggsound
accelerate launch inference.py --mapper_weights models/landscape/learned_embeds.pth --testset landscape
accelerate launch inference.py --mapper_weights models/audioset_drum/learned_embeds.pth --testset audioset_drum

此外,您有能力从自己的音频中生成视频,如下所示:

accelerate launch inference.py --mapper_weights models/vggsound/learned_embeds.pth --audio_path /audio/path
> python inference.py --help

usage: inference.py [-h] -m MODEL -p PROMPT [-n NEGATIVE_PROMPT] [-o OUTPUT_DIR]
                    [-B BATCH_SIZE] [-W WIDTH] [-H HEIGHT] [-T NUM_FRAMES]
                    [-WS WINDOW_SIZE] [-VB VAE_BATCH_SIZE] [-s NUM_STEPS]
                    [-g GUIDANCE_SCALE] [-i INIT_VIDEO] [-iw INIT_WEIGHT] [-f FPS]
                    [-d DEVICE] [-x] [-S] [-lP LORA_PATH] [-lR LORA_RANK] [-rw]

options:
  -h, --help            show this help message and exit
  -m MODEL, --model MODEL
                        HuggingFace repository or path to model checkpoint directory
  -p PROMPT, --prompt PROMPT
                        Text prompt to condition on
  -n NEGATIVE_PROMPT, --negative-prompt NEGATIVE_PROMPT
                        Text prompt to condition against
  -o OUTPUT_DIR, --output-dir OUTPUT_DIR
                        Directory to save output video to
  -B BATCH_SIZE, --batch-size BATCH_SIZE
                        Batch size for inference
  -W WIDTH, --width WIDTH
                        Width of output video
  -H HEIGHT, --height HEIGHT
                        Height of output video
  -T NUM_FRAMES, --num-frames NUM_FRAMES
                        Total number of frames to generate
  -WS WINDOW_SIZE, --window-size WINDOW_SIZE
                        Number of frames to process at once (defaults to full
                        sequence). When less than num_frames, a round robin diffusion
                        process is used to denoise the full sequence iteratively one
                        window at a time. Must be divide num_frames exactly!
  -VB VAE_BATCH_SIZE, --vae-batch-size VAE_BATCH_SIZE
                        Batch size for VAE encoding/decoding to/from latents (higher
                        values = faster inference, but more memory usage).
  -s NUM_STEPS, --num-steps NUM_STEPS
                        Number of diffusion steps to run per frame.
  -g GUIDANCE_SCALE, --guidance-scale GUIDANCE_SCALE
                        Scale for guidance loss (higher values = more guidance, but
                        possibly more artifacts).
  -i INIT_VIDEO, --init-video INIT_VIDEO
                        Path to video to initialize diffusion from (will be resized to
                        the specified num_frames, height, and width).
  -iw INIT_WEIGHT, --init-weight INIT_WEIGHT
                        Strength of visual effect of init_video on the output (lower
                        values adhere more closely to the text prompt, but have a less
                        recognizable init_video).
  -f FPS, --fps FPS     FPS of output video
  -d DEVICE, --device DEVICE
                        Device to run inference on (defaults to cuda).
  -x, --xformers        Use XFormers attnetion, a memory-efficient attention
                        implementation (requires `pip install xformers`).
  -S, --sdp             Use SDP attention, PyTorch's built-in memory-efficient
                        attention implementation.
  -lP LORA_PATH, --lora_path LORA_PATH
                        Path to Low Rank Adaptation checkpoint file (defaults to empty
                        string, which uses no LoRA).
  -lR LORA_RANK, --lora_rank LORA_RANK
                        Size of the LoRA checkpoint's projection matrix (defaults to
                        64).
  -rw, --remove-watermark
                        Post-process the videos with LAMA to inpaint ModelScope's
                        common watermarks.

致谢

我们的代码部分建立在文本到video-finetuning上

引用

如果您在研究中使用我们的工作,请引用以下论文:

@misc{yariv2023diverse,
      title={Diverse and Aligned Audio-to-Video Generation via Text-to-Video Model Adaptation}, 
      author={Guy Yariv and Itai Gat and Sagie Benaim and Lior Wolf and Idan Schwartz and Yossi Adi},
      year={2023},
      eprint={2309.16429},
      archivePrefix={arXiv},
      primaryClass={cs.LG}
}

执照

该存储库是根据许可证文件中发现的MIT许可证发布的。

下载源码

通过命令行克隆项目:

git clone https://github.com/guyyariv/TempoTokens.git