SAM 3D Body

repository·main·Indexed 25 days ago

https://github.com/facebookresearch/sam-3d-body

A promptable model for single-image full-body 3D human mesh recovery (HMR) that estimates human pose for the body, feet, and hands using the Momentum Human Rig (MHR) representation. The repository includes tools for model inference via a demo script and comprehensive data preparation pipelines for datasets including 3DPW, AI Challenger Keypoint, COCO, EgoExo4D, EgoHumans, Harmony4D, MPII, and SA1B.

Tokens
6.1K
Snippets
25
Records
33
Agent score
85%

What's inside SAM 3D Body

  1. Prepare the AI Challenger Keypoint Dataset

    main

    To prepare the AI Challenger Keypoint Dataset for use with SAM-3D-Body Data, you must organize the images into a specific directory structure and set an environment variable for easy referencing.

    1. Set the AIC_IMG_DIR environment variable to the path where your images are stored.
    2. Download the AI Challenger Keypoint images.
    3. Ensure the directory structure under $AIC_IMG_DIR matches the required format (containing test/images and train/images subdirectories).
    export AIC_IMG_DIR=/path/to/ai/challenger/images
  2. Prepare the Harmony4D Dataset for SAM-3D-Body Data

    main

    To prepare the Harmony4D dataset for use with SAM-3D-Body Data, you must set specific environment variables, download and extract the dataset, and run an undistortion script.

    1. Set Environment Variables: Define HARMONY4D_DATA_DIR (the root of the downloaded dataset) and HARMONY4D_IMG_DIR (where undistorted images will be saved).
    2. Download and Extract: Download the Harmony4D Dataset and extract it into $HARMONY4D_DATA_DIR. Ensure the directory structure contains test and train subdirectories.
    3. Undistort Images: Run the undistort_harmony4d.py script to process the images and save them to $HARMONY4D_IMG_DIR.
    # 1. Set environment variables
    export HARMONY4D_DATA_DIR=/path/to/harmony4d/dataset
    export HARMONY4D_IMG_DIR=/path/to/harmony4d/undistorted/images
    
    # 2. Run the undistortion script
    python scripts/harmony4d/undistort_harmony4d.py \
        --src_dir $HARMONY4D_DATA_DIR \
        --dst_dir $HARMONY4D_IMG_DIR
  3. Prepare the MPII Dataset for SAM-3D-Body Data

    main

    To prepare the MPII Dataset for use with SAM-3D-Body Data, you must set up the directory structure and download the required assets.

    1. Set the COCO_IMG_DIR environment variable to point to your image directory.
    2. Download the mpii_human_pose_v1.tar.gz archive.
    3. Extract the archive into your target directory ($MPII_IMG_DIR).

    The resulting directory structure must be:

    $MPII_IMG_DIR
    └── images
    # Set environment variable
    export COCO_IMG_DIR=/path/to/coco/images
    
    # Download and extract the dataset
    wget https://datasets.d2.mpi-inf.mpg.de/andriluka14cvpr/mpii_human_pose_v1.tar.gz
    tar zxvf mpii_human_pose_v1.tar.gz -C $MPII_IMG_DIR 
    rm mpii_human_pose_v1.tar.gz
  4. Prepare the COCO Dataset for SAM-3D-Body Data

    main

    To prepare the COCO dataset for use with SAM-3D-Body, you must set the COCO_IMG_DIR environment variable to your target directory, download the COCO 2014 image zips (train, val, and test), and extract them so that the directory structure contains test2014, train2014, and val2014 directly under the path specified by $COCO_IMG_DIR.

    # 1. Set the environment variable
    export COCO_IMG_DIR=/path/to/coco/images
    
    # 2. Download and extract the dataset
    cd $COCO_IMG_DIR
    wget http://images.cocodataset.org/zips/train2014.zip
    wget http://images.cocodataset.org/zips/val2014.zip
    wget http://images.cocodataset.org/zips/test2014.zip
    unzip train2014.zip 
    unzip val2014.zip 
    unzip test2014.zip 
    rm train2014.zip val2014.zip test2014.zip 
  5. Configure SAM 3D Body environment variables

    main

    Set the following environment variables to define where annotations are stored and where WebDataset archives should be outputted:

    • SAM3D_BODY_ANN_DIR: Path to the SAM 3D Body annotations directory.
    • SAM3D_BODY_WDS_DIR: Path to the directory for WebDataset output.
    export SAM3D_BODY_ANN_DIR=/path/to/sam3d/body/annotations
    export SAM3D_BODY_WDS_DIR=/path/to/sam3d/body/webdatasets
  6. Download SAM 3D Body Model Checkpoints

    main

    Model checkpoints are hosted on Hugging Face. You must request access on the specific repository page before you can download them. Once access is granted, ensure you are authenticated via Hugging Face to download the weights.

    Available models:

    • facebook/sam-3d-body-dinov3
    • facebook/sam-3d-body-vith

    Note: Access may be rejected if you are in a comprehensively sanctioned jurisdiction.

  7. Set up the SAM 3D Body data environment

    main

    Create and configure a conda environment specifically for dataset preparation. This includes installing PyTorch with CUDA support and several dependencies for processing 3D data, images, and datasets.

    conda create --name sam_3d_body_data python=3.9 -y
    conda activate sam_3d_body_data
    conda install pytorch=2.4.0 torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia -y
    pip install hdbscan pyntcloud==0.3.1 pykalman torchgeometry colour==0.1.5 flask==3.1.1 trimesh==4.7.3
    pip install pandas==2.0.3 numpy==1.26 pycolmap==0.3.0 yacs==0.1.8 projectaria-tools==1.3.3 opencv-python==4.7.0.72
    pip install datasets huggingface_hub webdataset pycocotools