Instructions to use getZuma/image-captioning with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use getZuma/image-captioning 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="getZuma/image-captioning")# Load model directly from transformers import AutoProcessor, AutoModelForVisualQuestionAnswering processor = AutoProcessor.from_pretrained("getZuma/image-captioning") model = AutoModelForVisualQuestionAnswering.from_pretrained("getZuma/image-captioning") - Notebooks
- Google Colab
- Kaggle
Commit ·
4ad5631
1
Parent(s): db1d42e
Fixed variable error.
Browse files- handler.py +3 -3
handler.py
CHANGED
|
@@ -24,7 +24,7 @@ class EndpointHandler():
|
|
| 24 |
self.processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
| 25 |
self.model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", torch_dtype=torch.float16, device_map="auto")
|
| 26 |
print(" $$$$ model loaded $$$$")
|
| 27 |
-
print(self.model.eval())
|
| 28 |
|
| 29 |
|
| 30 |
|
|
@@ -67,9 +67,9 @@ class EndpointHandler():
|
|
| 67 |
inputs = self.processor(raw_image, prompt, return_tensors="pt").to("cuda", torch.float16)
|
| 68 |
|
| 69 |
print("@@@@@@ generated_text @@@@@@@")
|
| 70 |
-
print(generated_text)
|
| 71 |
out = self.model.generate(**inputs)
|
| 72 |
-
|
|
|
|
| 73 |
|
| 74 |
print("captions", captions)
|
| 75 |
|
|
|
|
| 24 |
self.processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
|
| 25 |
self.model = Blip2ForConditionalGeneration.from_pretrained("Salesforce/blip2-opt-2.7b", torch_dtype=torch.float16, device_map="auto")
|
| 26 |
print(" $$$$ model loaded $$$$")
|
| 27 |
+
# print(self.model.eval())
|
| 28 |
|
| 29 |
|
| 30 |
|
|
|
|
| 67 |
inputs = self.processor(raw_image, prompt, return_tensors="pt").to("cuda", torch.float16)
|
| 68 |
|
| 69 |
print("@@@@@@ generated_text @@@@@@@")
|
|
|
|
| 70 |
out = self.model.generate(**inputs)
|
| 71 |
+
print("!!!!!!")
|
| 72 |
+
captions = self.processor.decode(out[0], skip_special_tokens=True)
|
| 73 |
|
| 74 |
print("captions", captions)
|
| 75 |
|