This project utilizes the Depth Anything V2 model (safetensors formats) Original repository.
Follow these steps to set up the project environment and install dependencies.
1. Clone the Repository (Optional)
If you haven't already, clone the repository to your local machine:
git clone https://github.com/yushan777/depth-anything-v2.git
cd depth-anything-v22. Create a Python Virtual Environment
It's highly recommended to use a virtual environment to manage project dependencies.
python3 -m venv venv
# Or python -m venv venv- This command creates a directory named
venvin your project folder containing a dedicated Python installation.
3. Activate the Virtual Environment
You need to activate the environment before installing packages. The command differs based on your operating system:
-
macOS / Linux (bash/zsh):
source venv/bin/activate -
Windows (Command Prompt):
venv\Scripts\activate.bat
-
Windows (PowerShell):
venv\Scripts\Activate.ps1
(Note: You might need to adjust your PowerShell execution policy:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process)You'll know the environment is active when you see
(venv)prepended to your command prompt.
4. Install PyTorch (Hardware-Specific)
Run the provided script to detect your hardware and install the correct PyTorch build (including torchvision and torchaudio):
python install_torch.py- This script checks for NVIDIA GPUs (installing the CUDA version if found) or Apple Silicon (installing the standard version with MPS support).
5. Install Remaining Dependencies
Install the other required packages listed in requirements.txt:
pip install -r requirements.txtTo run the model on an image:
python main.py \
--input path/to/your/image.jpg \
----output-dir path/to/save/depth_maps \
--model depth_anything_v2_vitl_fp32.safetensors- Replace
path/to/your/image.jpgandpath/to/save/depth_mapswith your actual file and dir paths. - Choose the desired model using the
--modelargument. - The script will automatically attempt to use a GPU (CUDA or MPS) if available, falling back to CPU otherwise.
6. Deactivate the Virtual Environment (When Done)