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
37e0974a
Unverified
Commit
37e0974a
authored
Mar 03, 2023
by
Matt
Committed by
GitHub
Mar 03, 2023
Browse files
Fix doctests for TFVisionTextDualEncoder (#21910)
parent
9f5bfe1b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
src/transformers/models/vision_text_dual_encoder/modeling_tf_vision_text_dual_encoder.py
...text_dual_encoder/modeling_tf_vision_text_dual_encoder.py
+6
-4
No files found.
src/transformers/models/vision_text_dual_encoder/modeling_tf_vision_text_dual_encoder.py
View file @
37e0974a
...
@@ -272,10 +272,10 @@ class TFVisionTextDualEncoderModel(TFPreTrainedModel):
...
@@ -272,10 +272,10 @@ class TFVisionTextDualEncoderModel(TFPreTrainedModel):
```python
```python
>>> from transformers import TFVisionTextDualEncoderModel, AutoTokenizer
>>> from transformers import TFVisionTextDualEncoderModel, AutoTokenizer
>>> model = TFVisionTextDualEncoderModel.from_pretrained("clip-italian/clip-italian")
>>> model = TFVisionTextDualEncoderModel.from_pretrained("clip-italian/clip-italian"
, from_pt=True
)
>>> tokenizer = AutoTokenizer.from_pretrained("clip-italian/clip-italian")
>>> tokenizer = AutoTokenizer.from_pretrained("clip-italian/clip-italian")
>>> inputs = tokenizer(["una foto di un gatto", "una foto di un cane"], padding=True, return_tensors="p
t
")
>>> inputs = tokenizer(["una foto di un gatto", "una foto di un cane"], padding=True, return_tensors="
n
p")
>>> text_features = model.get_text_features(**inputs)
>>> text_features = model.get_text_features(**inputs)
```"""
```"""
text_outputs
=
self
.
text_model
(
text_outputs
=
self
.
text_model
(
...
@@ -313,7 +313,7 @@ class TFVisionTextDualEncoderModel(TFPreTrainedModel):
...
@@ -313,7 +313,7 @@ class TFVisionTextDualEncoderModel(TFPreTrainedModel):
>>> import requests
>>> import requests
>>> from transformers import TFVisionTextDualEncoderModel, AutoImageProcessor
>>> from transformers import TFVisionTextDualEncoderModel, AutoImageProcessor
>>> model = VisionTextDualEncoderModel.from_pretrained("clip-italian/clip-italian")
>>> model =
TF
VisionTextDualEncoderModel.from_pretrained("clip-italian/clip-italian"
, from_pt=True
)
>>> image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224")
>>> image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224")
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
...
@@ -380,7 +380,7 @@ class TFVisionTextDualEncoderModel(TFPreTrainedModel):
...
@@ -380,7 +380,7 @@ class TFVisionTextDualEncoderModel(TFPreTrainedModel):
... ]
... ]
>>> images = [Image.open(requests.get(url, stream=True).raw) for url in urls]
>>> images = [Image.open(requests.get(url, stream=True).raw) for url in urls]
>>> inputs = processor(
>>> inputs = processor(
... text=["a photo of a cat", "a photo of a dog"], images=images, return_tensors="p
t
", padding=True
... text=["a photo of a cat", "a photo of a dog"], images=images, return_tensors="
n
p", padding=True
... )
... )
>>> outputs = model(
>>> outputs = model(
... input_ids=inputs.input_ids,
... input_ids=inputs.input_ids,
...
@@ -587,6 +587,8 @@ class TFVisionTextDualEncoderModel(TFPreTrainedModel):
...
@@ -587,6 +587,8 @@ class TFVisionTextDualEncoderModel(TFPreTrainedModel):
if
text_model
.
name
!=
"text_model"
:
if
text_model
.
name
!=
"text_model"
:
raise
ValueError
(
"text model must be created with the name `text_model`."
)
raise
ValueError
(
"text model must be created with the name `text_model`."
)
model
(
model
.
dummy_inputs
)
# Ensure model is fully built
return
model
return
model
@
property
@
property
...
...
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