Instructions to use trunks/blip-image-captioning-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use trunks/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="trunks/blip-image-captioning-base")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("trunks/blip-image-captioning-base") model = AutoModelForMultimodalLM.from_pretrained("trunks/blip-image-captioning-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files1 unmodified line23451 unmodified linelicense: mitlibrary_name: transformerspipeline_tag: image-to-text---1 unmodified line23456789101112131415161718192021222324252627281 unmodified linelicense: mitlibrary_name: transformerspipeline_tag: image-to-text---# Load modelfrom transformers import AutoProcessor, BlipForConditionalGenerationprocessor = AutoProcessor.from_pretrained("trunks/blip-image-captioning-base")model = BlipForConditionalGeneration.from_pretrained("trunks/blip-image-captioning-base")#prepare image for modelfrom PIL import Imagefrom IPython.display import displayimg1 = Image.open("imagepath/img.jpeg")width, height = img1.sizeimg1_resized = img1.resize((int(0.3 * width), int(0.3 * height))display(img1_resized)# testing imageinputs = processor(images=img1, return_tensors="pt")pixel_values = inputs.pixel_valuesgenerated_ids = model.generate(pixel_values=pixel_values, max_length=50)generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]print(generated_caption)
README.md+24-1