update
Browse files
app.py
CHANGED
@@ -1,19 +1,25 @@
|
|
1 |
from fastai.vision.all import *
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
|
|
|
|
5 |
|
6 |
model = load_learner('tradiotional_clothing_recognition-v1.pkl')
|
7 |
|
|
|
|
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
def recognize_image(image):
|
12 |
pred, idx, probs = model.predict(image)
|
13 |
-
return dict(zip(
|
14 |
|
15 |
-
image = gr.inputs.Image(shape=(192,192))
|
16 |
label = gr.outputs.Label(num_top_classes=5)
|
|
|
17 |
examples = [
|
18 |
'unknown-1.jpg',
|
19 |
'unknown-2.jpg',
|
@@ -21,10 +27,7 @@ examples = [
|
|
21 |
'unknown-12.jpg',
|
22 |
'unknown-16.jpg',
|
23 |
'unknown-18.jpg'
|
24 |
-
|
25 |
-
]
|
26 |
|
27 |
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
|
28 |
iface.launch(inline=False)
|
29 |
-
|
30 |
-
|
|
|
1 |
from fastai.vision.all import *
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Function to clean up the category name
|
5 |
+
def clean_category_name(category_name):
|
6 |
+
return category_name.replace("_", " ")
|
7 |
|
8 |
model = load_learner('tradiotional_clothing_recognition-v1.pkl')
|
9 |
|
10 |
+
# Get the original categories from the model
|
11 |
+
original_categories = model.dls.vocab
|
12 |
|
13 |
+
# Create a new list with cleaned category names
|
14 |
+
cleaned_categories = [clean_category_name(category) for category in original_categories]
|
15 |
|
16 |
def recognize_image(image):
|
17 |
pred, idx, probs = model.predict(image)
|
18 |
+
return dict(zip(cleaned_categories, map(float, probs)))
|
19 |
|
20 |
+
image = gr.inputs.Image(shape=(192, 192))
|
21 |
label = gr.outputs.Label(num_top_classes=5)
|
22 |
+
|
23 |
examples = [
|
24 |
'unknown-1.jpg',
|
25 |
'unknown-2.jpg',
|
|
|
27 |
'unknown-12.jpg',
|
28 |
'unknown-16.jpg',
|
29 |
'unknown-18.jpg'
|
30 |
+
]
|
|
|
31 |
|
32 |
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples=examples)
|
33 |
iface.launch(inline=False)
|
|
|
|