0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Hallo2を使って音声駆動の長時間高解像度ポートレート画像アニメーションを作成する方法

Last updated at Posted at 2024-10-20

はじめに

Hallo2は、音声入力に基づいて長時間かつ高解像度のポートレート画像アニメーションを生成できる最新のAI技術です。この記事では、Hallo2モデルをダウンロードし、Dockerを使って環境を構築し、実際に動かす方法を詳しく解説します。

Hallo2モデルのダウンロード

Hallo2モデルは複数の事前学習済みモデルで構成されています。以下のGit LFSコマンドを使用して、必要なモデルファイルをダウンロードします。

# audio_separator
git lfs pull --include="audio_separator/Kim_Vocal_2.onnx"

# CodeFormer
git lfs pull --include="CodeFormer/codeformer.pth"
git lfs pull --include="CodeFormer/vqgan_code1024.pth"

# face_analysis
git lfs pull --include="face_analysis/models/face_landmarker_v2_with_blendshapes.task"
git lfs pull --include="face_analysis/models/1k3d68.onnx"
git lfs pull --include="face_analysis/models/2d106det.onnx"
git lfs pull --include="face_analysis/models/genderage.onnx"
git lfs pull --include="face_analysis/models/glintr100.onnx"
git lfs pull --include="face_analysis/models/scrfd_10g_bnkps.onnx"

# facelib
git lfs pull --include="facelib/detection_mobilenet0.25_Final.pth"
git lfs pull --include="facelib/detection_Resnet50_Final.pth"
git lfs pull --include="facelib/parsing_parsenet.pth"
git lfs pull --include="facelib/yolov5l-face.pth"
git lfs pull --include="facelib/yolov5n-face.pth"

# hallo2
git lfs pull --include="hallo2/net_g.pth"
git lfs pull --include="hallo2/net.pth"

# motion_module
git lfs pull --include="motion_module/mm_sd_v15_v2.ckpt"

# realesrgan
git lfs pull --include="realesrgan/RealESRGAN_x2plus.pth"

# sd-vae-ft-mse
git lfs pull --include="sd-vae-ft-mse/diffusion_pytorch_model.safetensors"

# stable-diffusion-v1-5
git lfs pull --include="stable-diffusion-v1-5/unet/diffusion_pytorch_model.safetensors"

# wav2vec
git lfs pull --include="wav2vec/wav2vec2-base-960h/model.safetensors"

これらのコマンドを実行すると、Hallo2の動作に必要な全てのモデルファイルがダウンロードされます。

Dockerを使った環境構築

Hallo2を簡単に実行するために、Dockerを使用して環境を構築します。以下のDockerfileとdocker-compose.ymlファイルを使用します。

Dockerfile

FROM pytorch/pytorch:2.2.2-cuda12.1-cudnn8-runtime

WORKDIR /app

# システムの依存関係をインストール
RUN apt-get update && apt-get install -y \
    git \
    libgl1-mesa-glx \
    libglib2.0-0 \
    build-essential \
    libsm6 \
    libxext6 \
    libxrender-dev \
    && rm -rf /var/lib/apt/lists/*

# condaを使用してffmpegとx264をインストール
RUN conda install -y conda=24.9.2
RUN conda install -y -c conda-forge ffmpeg x264

# pipとsetuptoolsを更新
RUN pip install --no-cache-dir --upgrade pip setuptools wheel

# Pythonの依存関係をインストール
COPY requirements_cu12.txt .
RUN pip install --no-cache-dir -r requirements_cu12.txt
RUN pip install opencv-python opencv-contrib-python
RUN pip install --upgrade huggingface_hub diffusers opencv-python
# OpenCV-Pythonをヘッドレスバージョンで再インストール
RUN pip uninstall -y opencv-python && pip install --no-cache-dir opencv-python-headless

# プロジェクトファイルをコピー
COPY . .

docker-compose.yml

version: '3.8'
services:
  hallo2:
    build:
      context: .
      dockerfile: Dockerfile.cu12
    volumes:
      - .:/app
    tty: true
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]

これらのファイルを使用して、以下のコマンドでDockerイメージをビルドし、コンテナを起動します。

docker-compose up -d --build

Hallo2の実行方法

Hallo2を実行するには、以下のコマンドを使用します。

docker-compose exec hallo2 python scripts/inference_long.py --config ./configs/inference/long.yaml

このコマンドは、long.yaml設定ファイルを使用してHallo2の推論を実行します。必要に応じて、設定ファイルのパラメータを調整してください。

トラブルシューティング

  • GPUが認識されない場合は、NVIDIA Dockerがインストールされていることを確認してください。
  • メモリ不足エラーが発生した場合は、バッチサイズを小さくするか、より大きなメモリを持つGPUを使用してください。
  • モデルファイルのダウンロードに失敗した場合は、Git LFSが正しくインストールされていることを確認し、再度ダウンロードを試みてください。

まとめ

この記事では、Hallo2モデルをダウンロードし、Dockerを使って環境を構築し、実際に動かす方法を詳しく解説しました。Hallo2を使用することで、音声入力に基づいた長時間かつ高解像度のポートレート画像アニメーションを簡単に作成できます。この技術は、バーチャルYouTuberやデジタルアバター、教育コンテンツなど、様々な分野での応用が期待されています。

Hallo2の詳細な使用方法や最新の情報については、公式のGitHubリポジトリを参照してください。

Hallo2を使って、革新的なビジュアルコンテンツを作成しましょう!

Docker対応リポジトリ

原点

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?