Spaces:
Runtime error
Runtime error
Samuel Stevens
commited on
Commit
•
5cfebb1
1
Parent(s):
216fbaf
Add temperature
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import torch.nn.functional as F
|
|
|
4 |
from torchvision import transforms
|
5 |
|
6 |
-
from open_clip import create_model, get_tokenizer
|
7 |
from templates import openai_imagenet_template
|
8 |
|
9 |
model_str = "hf-hub:imageomics/bioclip"
|
@@ -44,7 +44,7 @@ def predict(img, cls_str: str) -> dict[str, float]:
|
|
44 |
|
45 |
img_features = model.encode_image(img.unsqueeze(0))
|
46 |
img_features = F.normalize(img_features, dim=-1)
|
47 |
-
logits = (img_features @ txt_features).squeeze()
|
48 |
probs = F.softmax(logits, dim=0).tolist()
|
49 |
return {cls: prob for cls, prob in zip(classes, probs)}
|
50 |
|
@@ -71,4 +71,3 @@ if __name__ == "__main__":
|
|
71 |
)
|
72 |
|
73 |
demo.launch()
|
74 |
-
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import torch.nn.functional as F
|
4 |
+
from open_clip import create_model, get_tokenizer
|
5 |
from torchvision import transforms
|
6 |
|
|
|
7 |
from templates import openai_imagenet_template
|
8 |
|
9 |
model_str = "hf-hub:imageomics/bioclip"
|
|
|
44 |
|
45 |
img_features = model.encode_image(img.unsqueeze(0))
|
46 |
img_features = F.normalize(img_features, dim=-1)
|
47 |
+
logits = (model.logit_scale.exp() * img_features @ txt_features).squeeze()
|
48 |
probs = F.softmax(logits, dim=0).tolist()
|
49 |
return {cls: prob for cls, prob in zip(classes, probs)}
|
50 |
|
|
|
71 |
)
|
72 |
|
73 |
demo.launch()
|
|