Prashanthsrn commited on
Commit
c7ebb32
·
verified ·
1 Parent(s): ebeb5b8

Update image_to_text.py

Browse files
Files changed (1) hide show
  1. image_to_text.py +6 -1
image_to_text.py CHANGED
@@ -1,13 +1,18 @@
1
  from transformers import BlipProcessor, BlipForConditionalGeneration
2
  import torch
 
3
 
4
  # Load the BLIP model and processor
5
  processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
6
  model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
7
 
8
  def generate_initial_caption(image):
 
 
 
 
9
  # Prepare the image for the model
10
- inputs = processor(images=image, return_tensors="pt")
11
 
12
  # Generate the caption
13
  with torch.no_grad():
 
1
  from transformers import BlipProcessor, BlipForConditionalGeneration
2
  import torch
3
+ from PIL import Image
4
 
5
  # Load the BLIP model and processor
6
  processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-large")
7
  model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-large")
8
 
9
  def generate_initial_caption(image):
10
+ # Ensure the image is in RGB format
11
+ if image.mode != "RGB":
12
+ image = image.convert("RGB")
13
+
14
  # Prepare the image for the model
15
+ inputs = processor(images=image, return_tensors="pt", padding=True)
16
 
17
  # Generate the caption
18
  with torch.no_grad():