Skip to content

Commit

Permalink
sam : update documentation to provide executable example (#596)
Browse files Browse the repository at this point in the history
Also adds the example sample image to the repo to simplify replication.

Signed-off-by: Jiri Podivin <[email protected]>
  • Loading branch information
jpodivin authored Nov 2, 2023
1 parent 54cec9f commit 4058f5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions examples/sam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,24 @@ cd ggml
# Install Python dependencies
python3 -m pip install -r requirements.txt

# Download PTH model
wget -P examples/sam/ https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth

# Convert PTH model to ggml
python convert-pth-to-ggml.py examples/sam/sam_vit_b_01ec64.pth . 1
python examples/sam/convert-pth-to-ggml.py examples/sam/sam_vit_b_01ec64.pth examples/sam/ 1

# Build ggml + examples
mkdir build && cd build
cmake .. && make -j4

# run inference
./bin/sam -t 16 -i ../img.jpg -m examples/sam/ggml-model-f16.bin
./bin/sam -t 16 -i ../examples/sam/example.jpg -m ../examples/sam/ggml-model-f16.bin
```

## Downloading and converting the model checkpoints

You can download a [model checkpoint](https://github.com/facebookresearch/segment-anything/tree/main#model-checkpoints) and convert it to `ggml` format using the script `convert-pth-to-ggml.py`:

```
# Convert PTH model to ggml
python convert-pth-to-ggml.py examples/sam/sam_vit_b_01ec64.pth . 1
```

## Example output on M2 Ultra
```
$ ▶ make -j sam && time ./bin/sam -t 8 -i img.jpg
Expand Down
Binary file added examples/sam/example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4058f5b

Please sign in to comment.