@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user