Unverified Commit 4cfe328b authored by fxmarty's avatar fxmarty Committed by GitHub
Browse files

Fix SAM example in documentation (#22887)

fix sam example
parent cb47293e
...@@ -39,12 +39,14 @@ The original code can be found [here](https://github.com/facebookresearch/segmen ...@@ -39,12 +39,14 @@ The original code can be found [here](https://github.com/facebookresearch/segmen
Below is an example on how to run mask generation given an image and a 2D point: Below is an example on how to run mask generation given an image and a 2D point:
```python ```python
import torch
from PIL import Image from PIL import Image
import requests import requests
from transformers import SamModelForMaskedGeneration, SamProcessor from transformers import SamModel, SamProcessor
model = SamModelForMaskedGeneration.from_pretrained("facebook/sam-vit-huge") device = "cuda" if torch.cuda.is_available() else "cpu"
processsor = SamProcessor.from_pretrained("facebook/sam-vit-huge") model = SamModel.from_pretrained("facebook/sam-vit-huge").to(device)
processor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
img_url = "https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png" img_url = "https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png"
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB") raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment