Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,43 +10,44 @@ model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms(
|
|
10 |
tokenizer = open_clip.get_tokenizer('hf-hub:Marqo/marqo-fashionSigLIP')
|
11 |
|
12 |
def predict(inp):
|
13 |
-
catgs = [
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
]
|
36 |
-
text = tokenizer(catgs)
|
37 |
-
image = preprocess_val(inp).unsqueeze(0)
|
38 |
|
39 |
-
with torch.no_grad(), torch.cuda.amp.autocast():
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
max_prob_idx = np.argmax(text_probs)
|
47 |
-
pred_lbl = catgs[max_prob_idx]
|
48 |
-
pred_lbl_prob = text_probs[0, max_prob_idx].item()
|
49 |
|
|
|
|
|
|
|
|
|
|
|
50 |
mw = ["men", "women", "boy", "girl"]
|
51 |
catgs = [
|
52 |
mw[0] + "s " + pred_lbl,
|
@@ -67,7 +68,8 @@ def predict(inp):
|
|
67 |
max_prob_idx = np.argmax(text_probs)
|
68 |
pred_lbl_f = mw[max_prob_idx]
|
69 |
pred_lbl_prob_f = text_probs[0, max_prob_idx].item()
|
70 |
-
tlt = f"{pred_lbl} <{100.0 * pred_lbl_prob:.1f}%> , {pred_lbl_f} <{100.0 * pred_lbl_prob_f:.1f}%>"
|
|
|
71 |
return(tlt)
|
72 |
|
73 |
gr.Interface(fn=predict,
|
|
|
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)
|
47 |
+
# pred_lbl = catgs[max_prob_idx]
|
48 |
+
# pred_lbl_prob = text_probs[0, max_prob_idx].item()
|
49 |
+
|
50 |
+
pred_lbl = "clothing"
|
51 |
mw = ["men", "women", "boy", "girl"]
|
52 |
catgs = [
|
53 |
mw[0] + "s " + pred_lbl,
|
|
|
68 |
max_prob_idx = np.argmax(text_probs)
|
69 |
pred_lbl_f = mw[max_prob_idx]
|
70 |
pred_lbl_prob_f = text_probs[0, max_prob_idx].item()
|
71 |
+
# tlt = f"{pred_lbl} <{100.0 * pred_lbl_prob:.1f}%> , {pred_lbl_f} <{100.0 * pred_lbl_prob_f:.1f}%>"
|
72 |
+
tlt = f"{pred_lbl_f} <{100.0 * pred_lbl_prob_f:.1f}%>"
|
73 |
return(tlt)
|
74 |
|
75 |
gr.Interface(fn=predict,
|