Skip to content

Commit 66f3b10

Browse files
committed
update for breaking sam2 changes
1 parent fd783b7 commit 66f3b10

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

label_studio_ml/examples/segment_anything_2_image/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,28 @@ cd label_studio_ml/examples/segment_anything_2_image
133133
pip install -r requirements.txt
134134
```
135135

136-
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)
136+
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)
137137

138+
You should now have the following folder structure:
139+
140+
| root directory
141+
| label-studio-ml-backend
142+
| label-studio-ml
143+
| examples
144+
| segment_anythng_2_image
145+
| sam2
146+
| sam2
147+
| checkpoints
138148

139149
3. Then you can start the ML backend on the default port `9090`:
140150

141151
```bash
142-
cd ../
143-
label-studio-ml start ./segment_anything_2_image
152+
cd ~/sam2
153+
label-studio-ml start ../label-studio-ml-backend/label-studio-ml/examples/segment_anything_2_image
144154
```
145155

156+
Due to breaking changes from Meta, it is CRUCIAL that you run this command from the sam2 directory at your root directory.
157+
146158
4. Connect running ML backend server to Label Studio: go to your project `Settings -> Machine Learning -> Add Model` and specify `http://localhost:9090` as a URL. Read more in the official [Label Studio documentation](https://labelstud.io/guide/ml#Connect-the-model-to-Label-Studio).
147159

148160
## Running with Docker (coming soon)

label_studio_ml/examples/segment_anything_2_image/model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import torch
22
import numpy as np
33
import os
4+
import sys
45
import pathlib
56
from typing import List, Dict, Optional
67
from uuid import uuid4
@@ -9,6 +10,9 @@
910
from label_studio_sdk.converter import brush
1011
from label_studio_sdk._extensions.label_studio_tools.core.utils.io import get_local_path
1112
from PIL import Image
13+
14+
ROOT_DIR = os.getcwd()
15+
sys.path.insert(0, ROOT_DIR)
1216
from sam2.build_sam import build_sam2
1317
from sam2.sam2_image_predictor import SAM2ImagePredictor
1418

@@ -29,7 +33,7 @@
2933

3034

3135
# build path to the model checkpoint
32-
sam2_checkpoint = str(pathlib.Path(__file__).parent / SEGMENT_ANYTHING_2_REPO_PATH / "checkpoints" / MODEL_CHECKPOINT)
36+
sam2_checkpoint = str(os.path.join(ROOT_DIR, "checkpoints", MODEL_CHECKPOINT))
3337

3438
sam2_model = build_sam2(MODEL_CONFIG, sam2_checkpoint, device=DEVICE)
3539

0 commit comments

Comments
 (0)