Instructions to use Salesforce/blip-image-captioning-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Salesforce/blip-image-captioning-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="Salesforce/blip-image-captioning-base")# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Salesforce/blip-image-captioning-base") model = AutoModelForMultimodalLM.from_pretrained("Salesforce/blip-image-captioning-base") - Notebooks
- Google Colab
- Kaggle
Length of captions
#14
by Gandharv - opened
How much long of a caption can this model generate. Is there a way to increase the length of captions, making it more detailed?
Hi @Gandharv
You can probably use sampling methods when calling generate, please have a look at https://huggingface.co/docs/transformers/generation_strategies for further details
You can also control the length of the generated text by setting max_new_tokens
You can do this
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
captioner(image, max_new_tokens=200, generate_kwargs={"min_length": 40})
You can also do this:
out = model.generate(**inputs, max_new_tokens=200, min_length=40)
But I found it only made the results worse.
@talrejanikhil . It worked for me! but I want to delve deeper. where can I get more of these details/ documentation