Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
4cfe328b
Unverified
Commit
4cfe328b
authored
Apr 20, 2023
by
fxmarty
Committed by
GitHub
Apr 20, 2023
Browse files
Fix SAM example in documentation (#22887)
fix sam example
parent
cb47293e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
docs/source/en/model_doc/sam.mdx
docs/source/en/model_doc/sam.mdx
+6
-4
No files found.
docs/source/en/model_doc/sam.mdx
View file @
4cfe328b
...
@@ -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
2
D
point
:
Below
is
an
example
on
how
to
run
mask
generation
given
an
image
and
a
2
D
point
:
```
python
```
python
import
torch
from
PIL
import
Image
from
PIL
import
Image
import
requests
import
requests
from
transformers
import
SamModel
ForMaskedGeneration
,
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"
)
...
@@ -93,4 +95,4 @@ Resources:
...
@@ -93,4 +95,4 @@ Resources:
##
SamModel
##
SamModel
[[
autodoc
]]
SamModel
[[
autodoc
]]
SamModel
-
forward
-
forward
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment