Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,46 +5,42 @@ import requests
|
|
| 5 |
import numpy as np
|
| 6 |
from PIL import Image
|
| 7 |
|
| 8 |
-
catgs = [
|
| 9 |
-
"Shirts",
|
| 10 |
-
"SetShirtsPants",
|
| 11 |
-
"SetJacketsPants",
|
| 12 |
-
"Pants",
|
| 13 |
-
"Jeans",
|
| 14 |
-
"JacketsCoats",
|
| 15 |
-
"Shoes",
|
| 16 |
-
"Underpants",
|
| 17 |
-
"Socks",
|
| 18 |
-
"Hats",
|
| 19 |
-
"Wallets",
|
| 20 |
-
"Bags",
|
| 21 |
-
"Scarfs",
|
| 22 |
-
"Parasols&Umbrellas",
|
| 23 |
-
"Necklaces",
|
| 24 |
-
"Towels&Robes",
|
| 25 |
-
"WallObjects",
|
| 26 |
-
"Rugs",
|
| 27 |
-
"Glassware",
|
| 28 |
-
"Mugs&Cups",
|
| 29 |
-
"OralCare"
|
| 30 |
-
]
|
| 31 |
|
| 32 |
model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:Marqo/marqo-fashionSigLIP')
|
| 33 |
tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionSigLIP')
|
| 34 |
|
| 35 |
-
text = tokenizer(catgs)
|
| 36 |
-
|
| 37 |
-
with torch.no_grad(), torch.cuda.amp.autocast():
|
| 38 |
-
text_features = model.encode_text(text)
|
| 39 |
-
text_features /= text_features.norm(dim=-1, keepdim=True)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
def predict(inp):
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
with torch.no_grad(), torch.cuda.amp.autocast():
|
| 46 |
image_features = model.encode_image(image)
|
| 47 |
-
image_features /= image_features.norm(dim=-1, keepdim=True)
|
|
|
|
|
|
|
| 48 |
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
|
| 49 |
|
| 50 |
max_prob_idx = np.argmax(text_probs)
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
from PIL import Image
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:Marqo/marqo-fashionSigLIP')
|
| 10 |
tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionSigLIP')
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def predict(inp):
|
| 13 |
+
catgs = [
|
| 14 |
+
"Shirts",
|
| 15 |
+
"SetShirtsPants",
|
| 16 |
+
"SetJacketsPants",
|
| 17 |
+
"Pants",
|
| 18 |
+
"Jeans",
|
| 19 |
+
"JacketsCoats",
|
| 20 |
+
"Shoes",
|
| 21 |
+
"Underpants",
|
| 22 |
+
"Socks",
|
| 23 |
+
"Hats",
|
| 24 |
+
"Wallets",
|
| 25 |
+
"Bags",
|
| 26 |
+
"Scarfs",
|
| 27 |
+
"Parasols&Umbrellas",
|
| 28 |
+
"Necklaces",
|
| 29 |
+
"Towels&Robes",
|
| 30 |
+
"WallObjects",
|
| 31 |
+
"Rugs",
|
| 32 |
+
"Glassware",
|
| 33 |
+
"Mugs&Cups",
|
| 34 |
+
"OralCare"
|
| 35 |
+
]
|
| 36 |
+
text = tokenizer(catgs)
|
| 37 |
+
image = preprocess_val(inp).unsqueeze(0)
|
| 38 |
|
| 39 |
with torch.no_grad(), torch.cuda.amp.autocast():
|
| 40 |
image_features = model.encode_image(image)
|
| 41 |
+
image_features /= image_features.norm(dim=-1, keepdim=True)
|
| 42 |
+
text_features = model.encode_text(text)
|
| 43 |
+
text_features /= text_features.norm(dim=-1, keepdim=True)
|
| 44 |
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
|
| 45 |
|
| 46 |
max_prob_idx = np.argmax(text_probs)
|