export AM_I_DOCKER=False
export BUILD_WITH_CUDA=True
export CUDA_HOME=/usr/local/cuda-12.1/
python -m pip install -e segment_anything
pip install --no-build-isolation -e GroundingDINO
pip install opencv-python pycocotools matplotlib onnxruntime onnx ipykernel
cd checkpoints
bash download_ckpts.sh
cd gdino_checkpoints
bash download_ckpts.sh
pip3 install torch torchvision torchaudio
(가장 추천하는 방법)CUDA environment variables
have been set correctly Grounding DINO Installation
for more details). environment variable
manually as follows export CUDA_HOME=/usr/local/cuda-12.1/
pip install -e .
pip install --no-build-isolation -e grounding_dino
Grounding DINO
가 이미 Huggingface를 통해 지원됩니다.Grounded SAM 2
model을 돌리기 위해 2가지 선택지를 제공합니다.simple and clear
)python grounded_sam2_hf_model_demo.py
[!NOTE]
🚨 If you encounter network issues while using theHuggingFace
model, you can resolve them by setting the appropriate mirror source asexport HF_ENDPOINT=https://hf-mirror.com
local pretrained Grounding DINO checkpoint
and inference with Grounding DINO original API
python grounded_sam2_local_demo.py
API token
first and run Grounded SAM 2 with Grounding DINO 1.5 as follows:pip install dds-cloudapi-sdk
python grounded_sam2_gd1.5_demo.py
Based on the strong tracking capability of SAM 2, we can combined it with Grounding DINO for open-set object segmentation and tracking. You can run the following scripts to get the tracking results with Grounded SAM 2:
python grounded_sam2_tracking_demo.py
./tracking_results
children_tracking_demo_video.mp4
We've supported different types of prompt for Grounded SAM 2 tracking demo:
We've also support video object tracking demo based on our stronger Grounding DINO 1.5
model and SAM 2
, you can try the following demo after applying the API keys for running Grounding DINO 1.5
:
python grounded_sam2_tracking_demo_with_gd1.5.py
Users can upload their own video file (e.g. assets/hippopotamus.mp4
) and specify their custom text prompts for grounding and tracking with Grounding DINO and SAM 2 by using the following scripts:
python grounded_sam2_tracking_demo_custom_video_input_gd1.0_hf_model.py
Users can upload their own video file (e.g. assets/hippopotamus.mp4
) and specify their custom text prompts for grounding and tracking with Grounding DINO 1.5 and SAM 2 by using the following scripts:
python grounded_sam2_tracking_demo_custom_video_input_gd1.5.py
You can specify the params in this file:
VIDEO_PATH = "./assets/hippopotamus.mp4"
TEXT_PROMPT = "hippopotamus."
OUTPUT_VIDEO_PATH = "./hippopotamus_tracking_demo.mp4"
API_TOKEN_FOR_GD1_5 = "Your API token" # api token for G-DINO 1.5
PROMPT_TYPE_FOR_VIDEO = "mask" # using SAM 2 mask prediction as prompt for video predictor
After running our demo code, you can get the tracking results as follows:
And we will automatically save the tracking visualization results in OUTPUT_VIDEO_PATH
.
[!WARNING]
We initialize the box prompts on the first frame of the input video. If you want to start from different frame, you can refineann_frame_idx
by yourself in our code.
In above demos, we only prompt Grounded SAM 2 in specific frame, which may not be friendly to find new object during the whole video. In this demo, we try to find new objects and assign them with new ID across the whole video, this function is still under develop. it's not that stable now.
Users can upload their own video files and specify custom text prompts for grounding and tracking using the Grounding DINO and SAM 2 frameworks. To do this, execute the script:
python grounded_sam2_tracking_demo_with_continuous_id.py
You can customize various parameters including:
text
: The grounding text prompt.video_dir
: Directory containing the video files.output_dir
: Directory to save the processed output.output_video_path
: Path for the output video.step
: Frame stepping for processing.box_threshold
: box threshold for groundingdino modeltext_threshold
: text threshold for groundingdino modelAfter running our demo code, you can get the tracking results as follows:
If you want to try Grounding DINO 1.5
model, you can run the following scripts after setting your API token:
python grounded_sam2_tracking_demo_with_continuous_id_gd1.5.py
This method could simply cover the whole lifetime of the object
python grounded_sam2_tracking_demo_with_continuous_id_plus.py