Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
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 |
|