Google Colab で Pyramid Flow を試す|npaka (original) (raw)

「Google Colab」で「Pyramid Flow」を試したのでまとめました。

【注意】Google Colab Pro/Pro+のA100で動作確認しています。

1. Pyramid Flow

Pyramid Flow」は、フローマッチングに基づく学習効率の高い自己回帰動画生成手法です。オープンソースのデータセットのみで学習することで、768pの解像度と24 FPSで高品質の10秒の動画を生成します。画像からの動画生成もサポートします。

2. Colabでの実行

Colabでの実行手順は、次のとおりです。

(1) パッケージのインストール。

# パッケージのインストール
!git clone https://github.com/jy0205/Pyramid-Flow
%cd Pyramid-Flow
!pip install -r requirements.txt

(2) メニュー「ランタイム → セッションを再起動する」で再起動後、元フォルダに移動。

# セッション再起動後に元のフォルダに移動
%cd Pyramid-Flow

(3) モデルのダウンロード。

from huggingface_hub import snapshot_download

# モデルのダウンロード
model_path = 'PATH'
snapshot_download("rain1011/pyramid-flow-sd3", local_dir=model_path, local_dir_use_symlinks=False, repo_type='model')

(4) Text-to-Videoの実行。

The beautiful city of Tokyo is bustling with activity. The camera moves through the bustling city streets, following people enjoying the beautiful cherry blossoms and shopping

【翻訳】
美しい東京の街は活気に満ちている。カメラは賑やかな街の通りを移動し、美しい桜やショッピングを楽しむ人々を追う。

# プロンプトの準備
prompt = "The beautiful city of Tokyo is bustling with activity. The camera moves through the bustling city streets, following people enjoying the beautiful cherry blossoms and shopping"

# 画像生成の実行
with torch.no_grad(), torch.cuda.amp.autocast(enabled=True, dtype=torch_dtype):
    frames = model.generate(
        prompt=prompt,
        num_inference_steps=[20, 20, 20],
        video_num_inference_steps=[10, 10, 10],
        height=768,
        width=1280,
        temp=16,  # temp=16: 5s, temp=31: 10s
        guidance_scale=9.0,  # 最初のフレームのガイダンス
        video_guidance_scale=5.0,  # 動画のガイダンス
        output_type="pil",
        save_memory=True,  # 十分なGPUメモリがある場合はFalseを設定
    )
export_to_video(frames, "./text_to_video_sample.mp4", fps=24)

生成に5分ほどかかりました。

(5) Image-to-Videoの実行。
assetsフォルダに以下の画像を配置。

・japanese_cityscape.jpg (1280x720)

FPV flying over the Japanese cityscape

【翻訳】
日本の街並みをFPVで飛行

# プロンプトの準備
image = Image.open('assets/japanese_cityscape.jpg').convert("RGB").resize((1280, 768))
prompt = "FPV flying over the Japanese cityscape"

# 画像生成の実行
with torch.no_grad(), torch.cuda.amp.autocast(enabled=True, dtype=torch_dtype):
    frames = model.generate_i2v(
        prompt=prompt,
        input_image=image,
        num_inference_steps=[10, 10, 10],
        temp=16,
        video_guidance_scale=4.0,
        output_type="pil",
        save_memory=True,  # 十分なGPUメモリがある場合はFalseを設定
    )
export_to_video(frames, "./image_to_video_sample.mp4", fps=24)

生成に5分ほどかかりました。