56 lines
1.7 KiB
Markdown
56 lines
1.7 KiB
Markdown
# Grounded-SAM-2
|
|
Grounded SAM 2: Ground and Track Anything with Grounding DINO and SAM 2
|
|
|
|
|
|
## Contents
|
|
|
|
|
|
## Installation
|
|
|
|
Since we need the CUDA compilation environment to compile the `Deformable Attention` operator used in Grounding DINO, we need to check whether the CUDA environment variables have been set correctly (which you can refer to [Grounding DINO Installation](https://github.com/IDEA-Research/GroundingDINO?tab=readme-ov-file#hammer_and_wrench-install) for more details). You can set the environment variable manually as follows if you want to build a local GPU environment for Grounding DINO to run Grounded SAM 2:
|
|
|
|
```bash
|
|
export CUDA_HOME=/path/to/cuda-12.1/
|
|
```
|
|
|
|
Install `segment-anything-2`:
|
|
|
|
```bash
|
|
pip install -e .
|
|
```
|
|
|
|
Install `grounding dino`:
|
|
|
|
```bash
|
|
pip install --no-build-isolation -e grounding_dino
|
|
```
|
|
|
|
Download the pretrained `grounding dino` and `sam 2` checkpoints:
|
|
|
|
```bash
|
|
cd checkpoints
|
|
bash download_ckpts.sh
|
|
```
|
|
|
|
```bash
|
|
cd gdino_checkpoints
|
|
wget https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth
|
|
wget https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha2/groundingdino_swinb_cogcoor.pth
|
|
```
|
|
|
|
## Run demo
|
|
### Grounded-SAM-2 Image Demo
|
|
|
|
Note that `Grounding DINO` has already been supported in [Huggingface](https://huggingface.co/IDEA-Research/grounding-dino-tiny), so we provide two choices for running `Grounded-SAM-2` model:
|
|
- Use huggingface API to inference Grounding DINO (which is simple and clear)
|
|
|
|
```bash
|
|
python grounded_sam2_hf_model_demo.py
|
|
```
|
|
|
|
- Load local pretrained Grounding DINO checkpoint and inference with Grounding DINO original API (make sure you've already downloaded the pretrained checkpoint)
|
|
|
|
```bash
|
|
python grounded_sam2_local_demo.py
|
|
```
|