Skip to content
Merged
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
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Examples

Various example scripts and applications of torchao and PyTorch in general.
9 changes: 4 additions & 5 deletions examples/sam2_amg_server/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
To run this example you need to download the vit_h checkpoint and put it into a local folder named checkpoints

You can find the checkpoint for vit_h here: https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth

To read the image you also need to install opencv-python: https://pypi.org/project/opencv-python/
## Example curl command
```
curl -X POST http://127.0.0.1:5000/upload -F 'image=@/path/to/file.jpg' --output path/to/output.png
```
Binary file added examples/sam2_amg_server/dog.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/sam2_amg_server/example.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand Down
117 changes: 0 additions & 117 deletions examples/sam2_amg_server/sam2_hiera_l.yaml

This file was deleted.

10 changes: 5 additions & 5 deletions examples/sam2_amg_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ class GenerateRequest(BaseModel):
num_steps: Optional[int] = 30
seed: Optional[int] = 42

def main():
def main(checkpoint_path):

from sam2.build_sam import build_sam2
from sam2.automatic_mask_generator import SAM2AutomaticMaskGenerator

device = "cuda"
sam2_checkpoint = "checkpoints/sam2_hiera_large.pt"
model_cfg = "sam2_hiera_l.yaml"
from pathlib import Path
sam2_checkpoint = Path(checkpoint_path) / Path("sam2.1_hiera_large.pt")
model_cfg = "configs/sam2.1/sam2.1_hiera_l.yaml"
logging.basicConfig(level=logging.INFO)

logging.info(f"Loading model: {sam2_checkpoint}")
logging.info(f"Loading model {sam2_checkpoint} with config {model_cfg}")
sam2 = build_sam2(model_cfg, sam2_checkpoint, device=device, apply_postprocessing=False)
sam2.to(device=device)

mask_generator = SAM2AutomaticMaskGenerator(sam2) #, points_per_batch=None)

Expand Down
Loading