LAM (Large Avatar Model)
repository·master·Indexed 21 days ago
https://github.com/aigc3d/lamA PyTorch implementation for creating ultra-realistic, one-shot animatable 3D Gaussian heads from a single image. Designed for high-speed animation, rendering, and low-latency interactive chatting, it includes a Gradio UI and CLI for inference. The repository also features a landmark detection pipeline utilizing STAR (Self-adaptive Ambiguity Reduction) loss for heatmap regression-based facial landmark detection.
What's inside LAM
- STAR (Self-adapTive Ambiguity Reduction) loss is a self-adaptive anisotropic direction loss designed for heatmap regression-based facial landmark detection. It addresses semantic ambiguity by using PCA to characterize the predicted distribution. This allows the loss to adaptively suppress prediction errors in directions of high ambiguity, mitigating the impact of ambiguous annotations during training.
Install dependencies for STAR Loss
masterEnsure your environment meets the following requirements:
- Python:
3.7.3 - PyTorch:
1.6.0 - Install other dependencies via
requirements.txt.
- Python:
Download LAM model weights and assets from HuggingFace
masterUse the
huggingface-clito download the necessary assets and model weights. This process involves downloading a temporary directory, extracting the assets and third-party models, and then downloading the specific model weights to themodel_zoodirectory.# Download assets huggingface-cli download 3DAIGC/LAM-assets --local-dir ./tmp tar -xf ./tmp/LAM_assets.tar && rm ./tmp/LAM_assets.tar tar -xf ./tmp/thirdparty_models.tar && rm -r ./tmp/ # Download model weights huggingface-cli download 3DAIGC/LAM-20K --local-dir ./model_zoo/lam_models/releases/lam/lam-20k/step_045500/huggingface-cli download 3DAIGC/LAM-assets --local-dir ./tmp tar -xf ./tmp/LAM_assets.tar && rm ./tmp/LAM_assets.tar tar -xf ./tmp/thirdparty_models.tar && rm -r ./tmp/ huggingface-cli download 3DAIGC/LAM-20K --local-dir ./model_zoo/lam_models/releases/lam/lam-20k/step_045500/Install Torch and Xformers for Windows
masterInstall the specific versions of Torch and xformers required for the environment using the CUDA 11.8 index URL.
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118 pip install -U xformers==0.0.26.post1 --index-url https://download.pytorch.org/whl/cu118Install LAM on Linux
masterTo set up the LAM environment on Linux, clone the repository and run the installation script corresponding to your CUDA version (12.1 or 11.8).
git clone https://github.com/aigc3d/LAM.git cd LAM # Install with Cuda 12.1 sh ./scripts/install/install_cu121.sh # Or Install with Cuda 11.8 sh ./scripts/install/install_cu118.shgit clone https://github.com/aigc3d/LAM.git cd LAM # Install with Cuda 12.1 sh ./scripts/install/install_cu121.sh # Or Install with Cuda 11.8 sh ./scripts/install/install_cu118.shPrepare datasets for STAR Loss
masterTo use the landmark detection implementation, you must organize your data into specific directory structures for WFLW, 300W, and COFW datasets.
- Download Raw Images: Obtain images from COFW, 300W, and WFLW.
- Preprocess: Follow the preprocessing steps used in ADNet and download metadata from the ADNet repository.
- Directory Structure: Organize files as follows:
|-- ${image_dir} |-- WFLW | -- WFLW_images |-- 300W | -- afw | -- helen | -- ibug | -- lfpw |-- COFW | -- train | -- test |-- ${annot_dir} |-- WFLW |-- train.tsv, test.tsv |-- 300W |-- train.tsv, test.tsv |--COFW |-- train.tsv, test.tsvDownload LAM Model Weights and Assets
masterYou can download the necessary assets and model weights using either
huggingface-cliormodelscope.Using HuggingFace
Requires
huggingface-cliinstalled.Using ModelScope
Requires
pip install modelscope.Note: After downloading, you must extract the assets and third-party models as shown in the commands below.
# HuggingFace Method huggingface-cli download 3DAIGC/LAM-assets --local-dir ./tmp tar -xf ./tmp/LAM_assets.tar && rm ./tmp/LAM_assets.tar tar -xf ./tmp/thirdparty_models.tar && rm -r ./tmp/ huggingface-cli download 3DAIGC/LAM-20K --local-dir ./model_zoo/lam_models/releases/lam/lam-20k/step_045500/ # ModelScope Method pip3 install modelscope modelscope download --model "Damo_XR_Lab/LAM-assets" --local_dir "./tmp/" tar -xf ./tmp/LAM_assets.tar && rm ./tmp/LAM_assets.tar tar -xf ./tmp/thirdparty_models.tar && rm -r ./tmp/ modelscope download "Damo_XR_Lab/LAM-20K" --local_dir "./model_zoo/lam_models/releases/lam/lam-20k/step_045500/"Install LAM on Windows
masterFor Windows users, a one-click installation package (supporting CUDA 12.8) is available. For detailed instructions, refer to the official Windows Install Guide in the repository.
- One-click package: Download Link
- Detailed Guide:
scripts/install/WINDOWS_INSTALL.md
Set up the environment for Exporting Chatting Avatars
masterTo export chatting avatars, you must install the Python FBX SDK (version 2020.2+) and Blender (version > 4.0.0).
Follow these steps:
- Install FBX SDK and dependencies: You can either install the FBX SDK from a tarball using the provided installation script or install a pre-built FBX-SDK Wheel. Additionally, install
pathlibandpatool. - Install Blender: Download and extract Blender version 4.0.0 or higher to a local directory.
- Download Assets: Download and extract the chatting avatar template files into the
assets/directory.
# Option A: Install FBX SDK via tarball and script wget https://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/share/aigc3d/data/LAM/fbxsdk_linux.tar tar -xf fbxsdk_linux.tar sh tools/install_fbx_sdk.sh # Option B: Install pre-built FBX-SDK Wheel wget https://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/share/aigc3d/data/LAM/fbx-2020.3.4-cp310-cp310-manylinux1_x86_64.whl pip install fbx-2020.3.4-cp310-cp310-manylinux1_x86_64.whl # Install other requirements pip install pathlib pip install patool # Download and extract sample files wget https://virutalbuy-public.oss-cn-hangzhou.aliyuncs.com/share/aigc3d/data/LAM/sample_oac.tar tar -xf sample_oac.tar -C assets/- Install FBX SDK and dependencies: You can either install the FBX SDK from a tarball using the provided installation script or install a pre-built FBX-SDK Wheel. Additionally, install
Download LAM model weights and assets from ModelScope
masterIf HuggingFace is inaccessible, use ModelScope to download the assets and weights. You must first install the
modelscopelibrary.# Install modelscope pip3 install modelscope # Download assets modelscope download --model "Damo_XR_Lab/LAM-assets" --local_dir "./tmp/" tar -xf ./tmp/LAM_assets.tar && rm ./tmp/LAM_assets.tar tar -xf ./tmp/thirdparty_models.tar && rm -r ./tmp/ # Download model weights modelscope download "Damo_XR_Lab/LAM-20K" --local_dir "./model_zoo/lam_models/releases/lam/lam-20k/step_045500/"pip3 install modelscope modelscope download --model "Damo_XR_Lab/LAM-assets" --local_dir "./tmp/" tar -xf ./tmp/LAM_assets.tar && rm ./tmp/LAM_assets.tar tar -xf ./tmp/thirdparty_models.tar && rm -r ./tmp/ modelscope download "Damo_XR_Lab/LAM-20K" --local_dir "./model_zoo/lam_models/releases/lam/lam-20k/step_045500/"Compile and Install Pytorch3d on Windows
masterInstalling Pytorch3d on Windows requires manual configuration of the
setup.pyfile to prevent compilation errors.- Set environment variables
DISTUTILS_USE_SDK=1andPYTORCH3D_NO_NINJA=1. - Clone the
pytorch3drepository. - Crucial Step: Modify
setup.pyby adding"-DWIN32_LEAN_AND_MEAN"to thenvcc_argslist. - Run the installation command.
set DISTUTILS_USE_SDK=1 set PYTORCH3D_NO_NINJA=1 git clone https://github.com/facebookresearch/pytorch3d.git cd pytorch3d # [Manual Step] Modify setup.py: add "-DWIN32_LEAN_AND_MEAN" in nvcc_args python setup.py install- Set environment variables
Run the Gradio app for Chatting Avatar Export
masterRun the
app_lam.pyscript using Gradio. You must provide the path to your Blender executable using the--blender_pathflag so the application can perform the export operations.# Example command python app_lam.py --blender_path ~/software/blender-4.0.2-linux-x64/blender