Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Port to sam2.1 #651

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions label_studio_ml/examples/segment_anything_2_image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions label_studio_ml/examples/segment_anything_2_image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions label_studio_ml/examples/segment_anything_2_image/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down