MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度技术分析:Hallo - 分层音频驱动的肖像图像动画

项目背景与痛点

图像动画是当前计算机视觉与音频处理领域中的一大挑战。传统方法往往侧重于静态图像的处理和合成,而忽略了基于音频驱动的多帧动画生成。Halfo,由复旦大学生成视觉实验室开发的开源项目,试图解决这一痛点。项目通过引入音频信号作为驱动源,实现高质量的肖像图像动画。

核心技术揭秘

Hallo 的核心理念是利用层次化的视觉合成技术进行肖像图像动画。该项目的技术栈主要基于深度学习框架 PyTorch,结合图像处理、音频信号分析等多领域知识。其算法流程主要包括音频特征提取、图像序列生成以及合成与细节调整。

graph TD A[音频输入] --> B[特征提取] B --> C[帧间关系建模] C --> D{"图像生成"} D -->|"肖像帧1"| E[合成与调整] D -->|"肖像帧2"| F[合成与调整] E --> G[动画序列1] F --> H[动画序列2] I[音频驱动] --> B I --> D G --> J[输出动画] H --> J

这段图展示了从音频输入到最终动画输出的整个处理流程。其中最为关键的是特征提取与图像生成阶段,通过对音频信号的细致分析,提取出用于驱动图像动画的关键特征。

功能亮点与差异

Halfo 的一大亮点在于其高度灵活的分层合成架构,能够根据不同音频信号生成具有丰富细节和动态表现的肖像动画。相比于一些依赖于数据库模板的方法,Hallo 通过深度学习直接从音频信号生成图像,灵活性与表现力显著提升。

应用场景与落地建议

此项目适合需要音频驱动图像现生成动画的业务场景,如虚拟主播、个性化视频制作等。在生产环境中,用户需特别注意音频信号的预处理,以确保特征提取的准确性。此外,还需准备好环境依赖,包括 GPU 支持环境,以提升模型运行效率。

综合评价

  • 优点:灵活的分层合成架构,基于音频信号生成动画的能力,对细节的出色表现。
  • 不足:目前的实时性有所欠缺,适合离线场景,对大规模数据集的支持仍有待优化。

总之,Halfo 项目为肖像图像动画提供了一种新的思路与实现方法,同时展现了在跨领域能源融合中的创新典范。

关于

GitHub 原始描述(英文)

Hallo: Hierarchical Audio-Driven Visual Synthesis for Portrait Image Animation

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
11359
价值分
5578
活跃状态
活跃

语言占比

Python

Release

README

Hallo: Hierarchical Audio-Driven Visual Synthesis for Portrait Image Animation

1Fudan University  2Baidu Inc  3ETH Zurich  4Nanjing University


📸 Showcase

https://github.com/fudan-generative-vision/hallo/assets/17402682/9d1a0de4-3470-4d38-9e4f-412f517f834c

🎬 Honoring Classic Films

Devil Wears Prada Green Book Infernal Affairs
Patch Adams Tough Love Shawshank Redemption

Explore more examples.

📰 News

  • 2024/06/28: 🎉🎉🎉 We are proud to announce the release of our model training code. Try your own training data. Here is tutorial.
  • 2024/06/21: 🚀🚀🚀 Cloned a Gradio demo on 🤗Huggingface space.
  • 2024/06/20: 🌟🌟🌟 Received numerous contributions from the community, including a Windows version, ComfyUI, WebUI, and Docker template.
  • 2024/06/15: ✨✨✨ Released some images and audios for inference testing on 🤗Huggingface.
  • 2024/06/15: 🎉🎉🎉 Launched the first version on 🫡GitHub.

🤝 Community Resources

Explore the resources developed by our community to enhance your experience with Hallo:

Thanks to all of them.

Join our community and explore these amazing resources to make the most out of Hallo. Enjoy and elevate their creative projects!

🔧️ Framework

abstract framework

⚙️ Installation

  • System requirement: Ubuntu 20.04/Ubuntu 22.04, Cuda 12.1
  • Tested GPUs: A100

Create conda environment:

  conda create -n hallo python=3.10
  conda activate hallo

Install packages with pip

  pip install -r requirements.txt
  pip install .

Besides, ffmpeg is also needed:

  apt-get install ffmpeg

🗝️️ Usage

The entry point for inference is scripts/inference.py. Before testing your cases, two preparations need to be completed:

  1. Download all required pretrained models.
  2. Prepare source image and driving audio pairs.
  3. Run inference.

📥 Download Pretrained Models

You can easily get all pretrained models required by inference from our HuggingFace repo.

Clone the pretrained models into ${PROJECT_ROOT}/pretrained_models directory by cmd below:

git lfs install
git clone https://huggingface.co/fudan-generative-ai/hallo pretrained_models

Or you can download them separately from their source repo:

Finally, these pretrained models should be organized as follows:

./pretrained_models/
|-- audio_separator/
|   |-- download_checks.json
|   |-- mdx_model_data.json
|   |-- vr_model_data.json
|   `-- Kim_Vocal_2.onnx
|-- face_analysis/
|   `-- models/
|       |-- face_landmarker_v2_with_blendshapes.task  # face landmarker model from mediapipe
|       |-- 1k3d68.onnx
|       |-- 2d106det.onnx
|       |-- genderage.onnx
|       |-- glintr100.onnx
|       `-- scrfd_10g_bnkps.onnx
|-- motion_module/
|   `-- mm_sd_v15_v2.ckpt
|-- sd-vae-ft-mse/
|   |-- config.json
|   `-- diffusion_pytorch_model.safetensors
|-- stable-diffusion-v1-5/
|   `-- unet/
|       |-- config.json
|       `-- diffusion_pytorch_model.safetensors
`-- wav2vec/
    `-- wav2vec2-base-960h/
        |-- config.json
        |-- feature_extractor_config.json
        |-- model.safetensors
        |-- preprocessor_config.json
        |-- special_tokens_map.json
        |-- tokenizer_config.json
        `-- vocab.json

🛠️ Prepare Inference Data

Hallo has a few simple requirements for input data:

For the source image:

  1. It should be cropped into squares.
  2. The face should be the main focus, making up 50%-70% of the image.
  3. The face should be facing forward, with a rotation angle of less than 30° (no side profiles).

For the driving audio:

  1. It must be in WAV format.
  2. It must be in English since our training datasets are only in this language.
  3. Ensure the vocals are clear; background music is acceptable.

We have provided some samples for your reference.

🎮 Run Inference

Simply to run the scripts/inference.py and pass source_image and driving_audio as input:

python scripts/inference.py --source_image examples/reference_images/1.jpg --driving_audio examples/driving_audios/1.wav

Animation results will be saved as ${PROJECT_ROOT}/.cache/output.mp4 by default. You can pass --output to specify the output file name. You can find more examples for inference at examples folder.

For more options:

usage: inference.py [-h] [-c CONFIG] [--source_image SOURCE_IMAGE] [--driving_audio DRIVING_AUDIO] [--output OUTPUT] [--pose_weight POSE_WEIGHT]
                    [--face_weight FACE_WEIGHT] [--lip_weight LIP_WEIGHT] [--face_expand_ratio FACE_EXPAND_RATIO]

options:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
  --source_image SOURCE_IMAGE
                        source image
  --driving_audio DRIVING_AUDIO
                        driving audio
  --output OUTPUT       output video file name
  --pose_weight POSE_WEIGHT
                        weight of pose
  --face_weight FACE_WEIGHT
                        weight of face
  --lip_weight LIP_WEIGHT
                        weight of lip
  --face_expand_ratio FACE_EXPAND_RATIO
                        face region

Training

Prepare Data for Training

The training data, which utilizes some talking-face videos similar to the source images used for inference, also needs to meet the following requirements:

  1. It should be cropped into squares.
  2. The face should be the main focus, making up 50%-70% of the image.
  3. The face should be facing forward, with a rotation angle of less than 30° (no side profiles).

Organize your raw videos into the following directory structure:

dataset_name/
|-- videos/
|   |-- 0001.mp4
|   |-- 0002.mp4
|   |-- 0003.mp4
|   `-- 0004.mp4

You can use any dataset_name, but ensure the videos directory is named as shown above.

Next, process the videos with the following commands:

python -m scripts.data_preprocess --input_dir dataset_name/videos --step 1
python -m scripts.data_preprocess --input_dir dataset_name/videos --step 2

Note: Execute steps 1 and 2 sequentially as they perform different tasks. Step 1 converts videos into frames, extracts audio from each video, and generates the necessary masks. Step 2 generates face embeddings using InsightFace and audio embeddings using Wav2Vec, and requires a GPU. For parallel processing, use the -p and -r arguments. The -p argument specifies the total number of instances to launch, dividing the data into p parts. The -r argument specifies which part the current process should handle. You need to manually launch multiple instances with different values for -r.

Generate the metadata JSON files with the following commands:

python scripts/extract_meta_info_stage1.py -r path/to/dataset -n dataset_name
python scripts/extract_meta_info_stage2.py -r path/to/dataset -n dataset_name

Replace path/to/dataset with the path to the parent directory of videos, such as dataset_name in the example above. This will generate dataset_name_stage1.json and dataset_name_stage2.json in the ./data directory.

Training

Update the data meta path settings in the configuration YAML files, configs/train/stage1.yaml and configs/train/stage2.yaml:

#stage1.yaml
data:
  meta_paths:
    - ./data/dataset_name_stage1.json

#stage2.yaml
data:
  meta_paths:
    - ./data/dataset_name_stage2.json

Start training with the following command:

accelerate launch -m \
  --config_file accelerate_config.yaml \
  --machine_rank 0 \
  --main_process_ip 0.0.0.0 \
  --main_process_port 20055 \
  --num_machines 1 \
  --num_processes 8 \
  scripts.train_stage1 --config ./configs/train/stage1.yaml
Accelerate Usage Explanation

The accelerate launch command is used to start the training process with distributed settings.

accelerate launch [arguments] {training_script} --{training_script-argument-1} --{training_script-argument-2} ...

Arguments for Accelerate:

  • -m, --module: Interpret the launch script as a Python module.
  • --config_file: Configuration file for Hugging Face Accelerate.
  • --machine_rank: Rank of the current machine in a multi-node setup.
  • --main_process_ip: IP address of the master node.
  • --main_process_port: Port of the master node.
  • --num_machines: Total number of nodes participating in the training.
  • --num_processes: Total number of processes for training, matching the total number of GPUs across all machines.

Arguments for Training:

  • {training_script}: The training script, such as scripts.train_stage1 or scripts.train_stage2.
  • --{training_script-argument-1}: Arguments specific to the training script. Our training scripts accept one argument, --config, to specify the training configuration file.

For multi-node training, you need to manually run the command with different machine_rank on each node separately.

For more settings, refer to the Accelerate documentation.

📅️ Roadmap

Status Milestone ETA
✅ Inference source code meet everyone on GitHub 2024-06-15
✅ Pretrained models on Huggingface 2024-06-15
✅ Releasing data preparation and training scripts 2024-06-28
🚀 Improving the model’s performance on Mandarin Chinese TBD
Other Enhancements
  • Enhancement: Test and ensure compatibility with Windows operating system. #39
  • Bug: Output video may lose several frames. #41
  • Bug: Sound volume affecting inference results (audio normalization).
  • Enhancement: Inference code logic optimization. This solution doesn’t show significant performance improvements. Trying other approaches.

📝 Citation

If you find our work useful for your research, please consider citing the paper:

@misc{xu2024hallo,
  title={Hallo: Hierarchical Audio-Driven Visual Synthesis for Portrait Image Animation},
  author={Mingwang Xu and Hui Li and Qingkun Su and Hanlin Shang and Liwei Zhang and Ce Liu and Jingdong Wang and Yao Yao and Siyu zhu},
  year={2024},
  eprint={2406.08801},
  archivePrefix={arXiv},
  primaryClass={cs.CV}
}

🌟 Opportunities Available

Multiple research positions are open at the Generative Vision Lab, Fudan University! Include:

  • Research assistant
  • Postdoctoral researcher
  • PhD candidate
  • Master students

Interested individuals are encouraged to contact us at [email protected] for further information.

⚠️ Social Risks and Mitigations

The development of portrait image animation technologies driven by audio inputs poses social risks, such as the ethical implications of creating realistic portraits that could be misused for deepfakes. To mitigate these risks, it is crucial to establish ethical guidelines and responsible use practices. Privacy and consent concerns also arise from using individuals’ images and voices. Addressing these involves transparent data usage policies, informed consent, and safeguarding privacy rights. By addressing these risks and implementing mitigations, the research aims to ensure the responsible and ethical development of this technology.

🤗 Acknowledgements

We would like to thank the contributors to the magic-animate, AnimateDiff, ultimatevocalremovergui, AniPortrait and Moore-AnimateAnyone repositories, for their open research and exploration.

If we missed any open-source projects or related articles, we would like to complement the acknowledgement of this specific work immediately.

👏 Community Contributors

Thank you to all the contributors who have helped to make this project better!

评论

暂无评论