Instructions to use google/pix2struct-textcaps-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use google/pix2struct-textcaps-base with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("image-to-text", model="google/pix2struct-textcaps-base")# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("google/pix2struct-textcaps-base") model = AutoModelForMultimodalLM.from_pretrained("google/pix2struct-textcaps-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -79,8 +79,8 @@ from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
|
|
| 79 |
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
| 80 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 81 |
|
| 82 |
-
model = Pix2StructForConditionalGeneration.from_pretrained("
|
| 83 |
-
processor = Pix2StructProcessor.from_pretrained("
|
| 84 |
|
| 85 |
# image only
|
| 86 |
inputs = processor(images=image, return_tensors="pt")
|
|
@@ -101,8 +101,8 @@ from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
|
|
| 101 |
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
| 102 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 103 |
|
| 104 |
-
model = Pix2StructForConditionalGeneration.from_pretrained("
|
| 105 |
-
processor = Pix2StructProcessor.from_pretrained("
|
| 106 |
|
| 107 |
# image only
|
| 108 |
inputs = processor(images=image, return_tensors="pt").to("cuda")
|
|
@@ -125,8 +125,8 @@ from transformers import Pix2StructForConditionalGeneration, Pix2StructProcessor
|
|
| 125 |
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
| 126 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 127 |
|
| 128 |
-
model = Pix2StructForConditionalGeneration.from_pretrained("
|
| 129 |
-
processor = Pix2StructProcessor.from_pretrained("
|
| 130 |
|
| 131 |
# image only
|
| 132 |
inputs = processor(images=image, return_tensors="pt").to("cuda", torch.bfloat16)
|
|
@@ -156,8 +156,8 @@ url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
|
| 156 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 157 |
text = "A picture of"
|
| 158 |
|
| 159 |
-
model = Pix2StructForConditionalGeneration.from_pretrained("
|
| 160 |
-
processor = Pix2StructProcessor.from_pretrained("
|
| 161 |
|
| 162 |
# image only
|
| 163 |
inputs = processor(images=image, text=text, return_tensors="pt")
|
|
|
|
| 79 |
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
| 80 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 81 |
|
| 82 |
+
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-textcaps-base")
|
| 83 |
+
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-textcaps-base")
|
| 84 |
|
| 85 |
# image only
|
| 86 |
inputs = processor(images=image, return_tensors="pt")
|
|
|
|
| 101 |
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
| 102 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 103 |
|
| 104 |
+
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-textcaps-base").to("cuda")
|
| 105 |
+
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-textcaps-base")
|
| 106 |
|
| 107 |
# image only
|
| 108 |
inputs = processor(images=image, return_tensors="pt").to("cuda")
|
|
|
|
| 125 |
url = "https://www.ilankelman.org/stopsigns/australia.jpg"
|
| 126 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 127 |
|
| 128 |
+
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-textcaps-base", torch_dtype=torch.bfloat16).to("cuda")
|
| 129 |
+
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-textcaps-base")
|
| 130 |
|
| 131 |
# image only
|
| 132 |
inputs = processor(images=image, return_tensors="pt").to("cuda", torch.bfloat16)
|
|
|
|
| 156 |
image = Image.open(requests.get(url, stream=True).raw)
|
| 157 |
text = "A picture of"
|
| 158 |
|
| 159 |
+
model = Pix2StructForConditionalGeneration.from_pretrained("google/pix2struct-textcaps-base")
|
| 160 |
+
processor = Pix2StructProcessor.from_pretrained("google/pix2struct-textcaps-base")
|
| 161 |
|
| 162 |
# image only
|
| 163 |
inputs = processor(images=image, text=text, return_tensors="pt")
|