From 5dd5b43b45959aa0ffa730d63093f9bb640859ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20=C3=89corchard?= Date: Tue, 15 Oct 2024 11:43:15 +0200 Subject: [PATCH] fix: Port to sam2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The repo `segment-anything-2` has been renamed `sam2`. The current model is sam2.1. Signed-off-by: Gaël Écorchard --- .../examples/segment_anything_2_image/Dockerfile | 6 +++--- label_studio_ml/examples/segment_anything_2_image/README.md | 4 ++-- .../examples/segment_anything_2_image/docker-compose.yml | 4 ++-- label_studio_ml/examples/segment_anything_2_image/model.py | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/label_studio_ml/examples/segment_anything_2_image/Dockerfile b/label_studio_ml/examples/segment_anything_2_image/Dockerfile index 25427f49..15915177 100644 --- a/label_studio_ml/examples/segment_anything_2_image/Dockerfile +++ b/label_studio_ml/examples/segment_anything_2_image/Dockerfile @@ -22,7 +22,7 @@ ENV PYTHONUNBUFFERED=1 \ WORKERS=2 \ THREADS=4 \ CUDA_HOME=/usr/local/cuda \ - SEGMENT_ANYTHING_2_REPO_PATH=/segment-anything-2 + SEGMENT_ANYTHING_2_REPO_PATH=/sam2 RUN conda install -c "nvidia/label/cuda-12.1.1" cuda -y ENV CUDA_HOME=/opt/conda \ @@ -38,8 +38,8 @@ RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \ pip3 install -r requirements.txt # install segment-anything-2 -RUN cd / && git clone --depth 1 --branch main --single-branch https://github.com/facebookresearch/segment-anything-2.git -WORKDIR /segment-anything-2 +RUN cd / && git clone --depth 1 --branch main --single-branch https://github.com/facebookresearch/sam2.git +WORKDIR /sam2 RUN --mount=type=cache,target=${PIP_CACHE_DIR},sharing=locked \ pip3 install -e . RUN cd checkpoints && ./download_ckpts.sh diff --git a/label_studio_ml/examples/segment_anything_2_image/README.md b/label_studio_ml/examples/segment_anything_2_image/README.md index 97e97b3d..9169dd47 100644 --- a/label_studio_ml/examples/segment_anything_2_image/README.md +++ b/label_studio_ml/examples/segment_anything_2_image/README.md @@ -133,7 +133,7 @@ cd label_studio_ml/examples/segment_anything_2_image pip install -r requirements.txt ``` -2. Download [`segment-anything-2` repo](https://github.com/facebookresearch/segment-anything-2) into the root directory. Install SegmentAnything model and download checkpoints using [the official Meta documentation](https://github.com/facebookresearch/segment-anything-2?tab=readme-ov-file#installation) +2. Download [`segment-anything-2` repo](https://github.com/facebookresearch/sam2) into the root directory. Install SegmentAnything model and download checkpoints using [the official Meta documentation](https://github.com/facebookresearch/sam2?tab=readme-ov-file#installation) 3. Then you can start the ML backend on the default port `9090`: @@ -179,4 +179,4 @@ The following common parameters are available: ## Customization -The ML backend can be customized by adding your own models and logic inside the `./segment_anything_2` directory. +The ML backend can be customized by adding your own models and logic inside the `./sam2` directory. diff --git a/label_studio_ml/examples/segment_anything_2_image/docker-compose.yml b/label_studio_ml/examples/segment_anything_2_image/docker-compose.yml index 8df4a9d0..49ef0973 100644 --- a/label_studio_ml/examples/segment_anything_2_image/docker-compose.yml +++ b/label_studio_ml/examples/segment_anything_2_image/docker-compose.yml @@ -24,9 +24,9 @@ services: # specify device - DEVICE=cuda # or 'cpu' (coming soon) # SAM2 model config - - MODEL_CONFIG=sam2_hiera_l.yaml + - MODEL_CONFIG=configs/sam2.1/sam2.1_hiera_l.yaml # SAM2 checkpoint - - MODEL_CHECKPOINT=sam2_hiera_large.pt + - MODEL_CHECKPOINT=sam2.1_hiera_large.pt # Specify the Label Studio URL and API key to access # uploaded, local storage and cloud storage files. diff --git a/label_studio_ml/examples/segment_anything_2_image/model.py b/label_studio_ml/examples/segment_anything_2_image/model.py index 9d29c9f1..5a4e214c 100644 --- a/label_studio_ml/examples/segment_anything_2_image/model.py +++ b/label_studio_ml/examples/segment_anything_2_image/model.py @@ -14,9 +14,9 @@ DEVICE = os.getenv('DEVICE', 'cuda') -SEGMENT_ANYTHING_2_REPO_PATH = os.getenv('SEGMENT_ANYTHING_2_REPO_PATH', 'segment-anything-2') -MODEL_CONFIG = os.getenv('MODEL_CONFIG', 'sam2_hiera_l.yaml') -MODEL_CHECKPOINT = os.getenv('MODEL_CHECKPOINT', 'sam2_hiera_large.pt') +SEGMENT_ANYTHING_2_REPO_PATH = os.getenv('SEGMENT_ANYTHING_2_REPO_PATH', 'sam2') +MODEL_CONFIG = os.getenv('MODEL_CONFIG', 'configs/sam2.1/sam2.1_hiera_l.yaml') +MODEL_CHECKPOINT = os.getenv('MODEL_CHECKPOINT', 'sam2.1_hiera_large.pt') if DEVICE == 'cuda': # use bfloat16 for the entire notebook