VGGT (Visual Geometry Grounded Transformer)
repository·main·Indexed 12 days ago
https://github.com/facebookresearch/vggtA feed-forward neural network designed to infer 3D scene attributes—including camera parameters, depth maps, point maps, and 3D point tracks—from one or more image views in seconds. It supports zero-shot single-view reconstruction and can export results to COLMAP format for integration with tools like gsplat.
What's inside VGGT
- VGGT can perform single-view 3D reconstruction without explicit training for the task. The model infers 3D structure directly from the tokens of a single view image, meaning you do not need to duplicate the single-view image into a pair. It has shown competitive or better results compared to state-of-the-art monocular depth estimation methods like DepthAnything v2 or MoGe.
Masking unwanted pixels
mainYou can mask unwanted pixels (e.g., sky, water, or reflections) by setting their values to 0 or 1. Precise segmentation is not required; simple bounding box masks are effective.Commercial usage and model checkpoints
mainStandard model checkpoints may have different licensing terms. Only the specific checkpoint hosted on Hugging Face allows for commercial usage. This commercial checkpoint (VGGT-1B-Commercial) achieves performance levels comparable to or slightly better than the original (e.g., AUC@30: 90.37 vs 89.98 on the Co3D dataset).
https://huggingface.co/facebook/VGGT-1B-CommercialInstall VGGT
mainTo install VGGT, clone the repository and install the required dependencies using
pip.Required dependencies include
torch,torchvision,numpy,Pillow, andhuggingface_hub.git clone git@github.com:facebookresearch/vggt.git cd vggt pip install -r requirements.txtIntegrate with Gaussian Splatting (gsplat)
mainThe COLMAP files exported by VGGT can be used directly for training with
gsplat.Workflow:
- Export COLMAP files using
demo_colmap.py. - Install
gsplat(version1.3.0is recommended). - Run the trainer pointing to your scene directory.
cd gsplat python examples/simple_trainer.py default --data_factor 1 --data_dir /YOUR/SCENE_DIR/ --result_dir /YOUR/RESULT_DIR/- Export COLMAP files using
Install PyTorch and torchvision prerequisites
mainBefore installing VGGT, you must manually install
torchandtorchvisionto prevent CUDA version mismatches. It is recommended to install PyTorch 2.3.1 with CUDA 12.1.# install pytorch 2.3.1 with cuda 12.1 pip install torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu121Quick Start: Run VGGT inference
mainYou can run VGGT inference with a few lines of code. The model automatically downloads pretrained weights from Hugging Face on the first run.
Note on Precision:
bfloat16is supported on Ampere GPUs (Compute Capability 8.0+). For older GPUs, usefloat16.import torch from vggt.models.vggt import VGGT from vggt.utils.load_fn import load_and_preprocess_images device = "cuda" if torch.cuda.is_available() else "cpu" # bfloat16 is supported on Ampere GPUs (Compute Capability 8.0+) dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] >= 8 else torch.float16 # Initialize the model and load the pretrained weights. model = VGGT.from_pretrained("facebook/VGGT-1B").to(device) # Load and preprocess example images (replace with your own image paths) image_names = ["path/to/imageA.png", "path/to/imageB.png", "path/to/imageC.png"] images = load_and_preprocess_images(image_names).to(device) with torch.no_grad(): with torch.cuda.amp.autocast(dtype=dtype): # Predict attributes including cameras, depth maps, and point maps. predictions = model(images)Tune learning rates for VGGT training
mainThe effective batch size is calculated as
batch_size_per_gpu * num_gpus. Because the learning rate depends on this effective batch size, it is recommended to test several values.Suggested starting values to try:
5e-61e-55e-51e-45e-4
Install and prepare VGGT for training
mainTo set up the VGGT training environment, follow these steps:
Install the package in editable mode:
pip install -e .Prepare Datasets:
- Download the Co3D dataset from the official repository.
- Download the required annotation files from Hugging Face.
pip install -e .Visualize reconstructions with Gradio or Viser
mainTo use the interactive visualization tools, first install the demo dependencies:
pip install -r requirements_demo.txtGradio Web Interface
Launch a local web interface to upload images/videos and interactively explore the 3D scene:
python demo_gradio.pyViser 3D Viewer
Run reconstruction and visualize point clouds in
viser. This script requires a folder containing only image files:python demo_viser.py --image_folder path/to/your/images/folderUse the
--use_point_mapflag to use the point cloud from the point map branch instead of the depth-based reconstruction.pip install -r requirements_demo.txt # Gradio python demo_gradio.py # Viser python demo_viser.py --image_folder path/to/your/images/folderInstall and run VGGT with uv
mainUse uv to run the Gradio demo, ensuring the
demoextra is included.uv run --extra demo demo_gradio.pyInstall and run VGGT with pixi
mainUse pixi to create a reproducible environment and run the Gradio demo.
pixi run -e python demo_gradio.py