ryaalbr commited on
Commit
94fab67
·
1 Parent(s): fbb03a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -24,10 +24,11 @@ dataset = load_dataset("jamescalam/unsplash-25k-photos", split="train") # all 2
24
  height = 256 # height for resizing images
25
 
26
  def predict(image, labels):
27
- inputs = processor(text=[f"a photo of {c}" for c in labels], images=image, return_tensors="pt", padding=True)
28
- outputs = model(**inputs)
29
- logits_per_image = outputs.logits_per_image # this is the image-text similarity score
30
- probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities
 
31
  return {k: float(v) for k, v in zip(labels, probs[0])}
32
 
33
 
 
24
  height = 256 # height for resizing images
25
 
26
  def predict(image, labels):
27
+ with torch.no_grad():
28
+ inputs = processor(text=[f"a photo of {c}" for c in labels], images=image, return_tensors="pt", padding=True)
29
+ outputs = model(**inputs)
30
+ logits_per_image = outputs.logits_per_image # this is the image-text similarity score
31
+ probs = logits_per_image.softmax(dim=1).cpu().numpy() # we can take the softmax to get the label probabilities
32
  return {k: float(v) for k, v in zip(labels, probs[0])}
33
 
34