Follow-Your-Pose

repository·main·Indexed 23 days ago

https://github.com/mayuelala/followyourpose

A pose-guided text-to-video generation framework (AAAI 2024) that tunes text-to-image models to generate character videos based on pose and text descriptions. It supports the use of pose-free videos as input and provides tools for training via accelerate, inference using skeleton videos, and a Gradio-based web interface for interactive generation.

Tokens
2.4K
Snippets
10
Records
14
Agent score
80%

What's inside Follow-Your-Pose

  1. Install xformers for A100 GPUs

    main

    If you encounter stability issues with the standard xformers installation, you can attempt to install it using the following specific wheel:

    wget https://github.com/ShivamShrirao/xformers-wheels/releases/download/4c06c79/xformers-0.0.15.dev0+4c06c79.d20221201-cp38-cp38-linux_x86_64.whl
    pip install xformers-0.0.15.dev0+4c06c79.d20221201-cp38-cp38-linux_x86_64.whl
  2. Train Follow-Your-Pose

    main

    To fine-tune text-to-image diffusion models (like Stable Diffusion 1.4) for text-to-video generation, use the train_followyourpose.py script with accelerate. This command is configured for multi-GPU training on 8 GPUs.

    TORCH_DISTRIBUTED_DEBUG=DETAIL accelerate launch \
        --multi_gpu --num_processes=8 --gpu_ids '0,1,2,3,4,5,6,7' \
        train_followyourpose.py \
        --config="configs/pose_train.yaml" 
  3. Setup the Follow-Your-Pose environment

    main

    Follow-Your-Pose is trained using CUDA 11, accelerate, and xformers on 8x A100 GPUs. To set up a local environment, create a new Conda environment and install the required dependencies.

    It is highly recommended to use xformers on A100 GPUs to reduce memory usage and improve runtime. If standard installation is unstable, you can use a specific wheel.

    The environment is similar to Tune-A-Video.

    conda create -n fupose python=3.8
    conda activate fupose
    
    pip install -r requirements.txt
  4. Run Inference for Pose-Guided Video Generation

    main

    Once training is complete, run the txt2video.py script to generate videos. You must provide a configuration file and a path to a skeleton video.

    Note on Skeleton Videos: You can generate skeleton videos using mmpose (using HRNet). Ensure you replace the background of your skeleton video with black.

    TORCH_DISTRIBUTED_DEBUG=DETAIL accelerate launch \
        --gpu_ids '0' \
        txt2video.py \
        --config="configs/pose_sample.yaml" \
        --skeleton_path="./pose_example/vis_ikun_pose2.mov"
  5. Configure Model Checkpoints

    main

    To perform inference, you need to download the pretrained checkpoints from Hugging Face and place them in the checkpoints directory following this structure:

    FollowYourPose
    ├── checkpoints
    │   ├── followyourpose_checkpoint-1000
    │   │   ├──...
    │   ├── stable-diffusion-v1-4
    │   │   ├──...
    │   └── pose_encoder.pth
  6. Run the Follow Your Pose Gradio Demo

    main

    The app.py file serves as the entrypoint for a Gradio-based web interface that allows users to perform pose-guided text-to-video generation. The interface accepts an input video (either raw or skeleton), a text prompt, and various sampling/cropping parameters to generate a new video.

    To run the demo, ensure you have the necessary dependencies installed and execute the script. The application initializes a pipeline using merge_config_then_run() and launches a web server on 0.0.0.0:80.

  7. Download Follow Your Pose weights

    main

    Weights are hosted on HuggingFace. You must install Git LFS, clone the YueMafighting/FollowYourPose_v1 repository, and move the contents into a checkpoints/ directory within the project root.

    %mkdir checkpoints
    !git lfs install
    !git clone https://huggingface.co/YueMafighting/FollowYourPose_v1
    %mv /content/FollowYourPose/FollowYourPose_v1/* /content/FollowYourPose/checkpoints/
    %rm -rf FollowYourPose_v1
  8. Install the Follow Your Pose environment

    main

    To set up the environment, you need to configure Python alternatives, install system dependencies, clone the repository, and install specific versions of PyTorch, Diffusers, and Transformers.

    Note: The installation process involves specific Python versions (3.8/3.9) and CUDA-specific wheels for xformers and torch.

    # Install system dependencies and Python setup
    !update-alternatives --install /usr/local/bin/python3 python3 /usr/bin/python3.8 2  
    !update-alternatives --install /usr/local/bin/python3 python3 /usr/bin/python3.9 1  
    !apt-get update
    !apt install software-properties-common
    !apt-get install python3-pip
    
    # Clone and install Python requirements
    !git clone https://github.com/mayuelala/FollowYourPose.git
    %cd /content/FollowYourPose
    !python3.8 -m pip install -q -U --pre triton
    !python3.8 -m pip install -q diffusers==0.11.1 torch==1.13.1 transformers==4.26.0 bitsandbytes==0.35.4 imageio-ffmpeg xformers==0.0.16 --extra-index-url https://download.pytorch.org/whl/cu113
    !python3.8 -m pip install -r requirements.txt
  9. Cite Follow Your Pose

    main

    If you use this project in your research, please cite the following paper:

    @article{ma2023follow,
      title={Follow Your Pose: Pose-Guided Text-to-Video Generation using Pose-Free Videos},
      author={Ma, Yue and He, Yingqing and Cun, Xiaodong and Wang, Xintao and Shan, Ying and Li, Xiu and Chen, Qifeng},
      journal={arXiv preprint arXiv:2304.01186},
      year={2023}
    }
  10. Run pose-guided text-to-video sampling

    main

    Use the txt2video.py script with accelerate launch to generate videos guided by a skeleton video.

    Important Configuration Requirements:

    1. GPU Memory Management: If you encounter memory issues, set video_length=8 in ./config/pose_sample.yaml.
    2. Skeleton Alignment: Ensure the skeleton frame length (defined in ./followyourpose/pipelines/pipeline_followyourpose.py:422) matches the video_length specified in your config.

    Generated videos are saved to ./output/samples.

    %cd /content/FollowYourPose
    !TORCH_DISTRIBUTED_DEBUG=DETAIL accelerate launch txt2video.py --config="configs/pose_sample.yaml" --skeleton_path="./pose_example/vis_ikun_pose2.mov"