ybelkada commited on
Commit
835fa4a
1 Parent(s): f956ef0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +14 -13
README.md CHANGED
@@ -46,23 +46,24 @@ The SAM model is made up of 3 modules:
46
  ## Prompted-Mask-Generation
47
 
48
  ```python
49
- >>> from PIL import Image
50
- >>> import requests
51
- >>> from transformers import SamModel, SamProcessor
52
- >>> model = SamModel.from_pretrained("facebook/sam-vit-huge")
53
- >>> processsor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
54
-
55
- >>> img_url = "https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png"
56
- >>> raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB")
57
- >>> input_points = [[[450, 600]]]
 
58
  ```
59
 
60
 
61
  ```python
62
- >>> inputs = processor(raw_image, input_points=input_points, return_tensors="pt").to(device)
63
- >>> outputs = model(**inputs)
64
- >>> masks = processor.image_processor.post_process_masks(outputs.pred_masks.cpu(), inputs["original_sizes"].cpu(), inputs["reshaped_input_sizes"].cpu())
65
- >>> scores = outputs.iou_scores
66
  ```
67
  Among other arguments to generate masks, you can pass 2D locations on the approximate position of your object of interest, a bounding box wrapping the object of interest (the format should be x, y coordinate of the top right and bottom left point of the bounding box), a segmentation mask. At this time of writing, passing a text as input is not supported by the official model according to [the official repository](https://github.com/facebookresearch/segment-anything/issues/4#issuecomment-1497626844).
68
  For more details, refer to this notebook, which shows a walk throught of how to use the model, with a visual example!
 
46
  ## Prompted-Mask-Generation
47
 
48
  ```python
49
+ from PIL import Image
50
+ import requests
51
+ from transformers import SamModel, SamProcessor
52
+
53
+ model = SamModel.from_pretrained("facebook/sam-vit-huge")
54
+ processsor = SamProcessor.from_pretrained("facebook/sam-vit-huge")
55
+
56
+ img_url = "https://huggingface.co/ybelkada/segment-anything/resolve/main/assets/car.png"
57
+ raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB")
58
+ input_points = [[[450, 600]]] # 2D localization of a window
59
  ```
60
 
61
 
62
  ```python
63
+ inputs = processor(raw_image, input_points=input_points, return_tensors="pt").to(device)
64
+ outputs = model(**inputs)
65
+ masks = processor.image_processor.post_process_masks(outputs.pred_masks.cpu(), inputs["original_sizes"].cpu(), inputs["reshaped_input_sizes"].cpu())
66
+ scores = outputs.iou_scores
67
  ```
68
  Among other arguments to generate masks, you can pass 2D locations on the approximate position of your object of interest, a bounding box wrapping the object of interest (the format should be x, y coordinate of the top right and bottom left point of the bounding box), a segmentation mask. At this time of writing, passing a text as input is not supported by the official model according to [the official repository](https://github.com/facebookresearch/segment-anything/issues/4#issuecomment-1497626844).
69
  For more details, refer to this notebook, which shows a walk throught of how to use the model, with a visual example!