lukelike1001
commited on
Commit
•
0fc83e6
1
Parent(s):
4633480
neater output
Browse files
app.py
CHANGED
@@ -25,22 +25,11 @@ def predict_plant(path):
|
|
25 |
img_array = tf.keras.utils.img_to_array(img)
|
26 |
img_array = tf.expand_dims(img_array, 0)
|
27 |
|
28 |
-
# find the
|
29 |
predictions = model.predict(img_array)
|
30 |
score = tf.nn.softmax(predictions[0])
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
# convert the folder names into English words then return the three likeliest probabilities
|
35 |
-
output = []
|
36 |
-
for i in top_three:
|
37 |
-
words = class_names[i].split("_")
|
38 |
-
name = " ".join([word.capitalize() for word in words])
|
39 |
-
output.append(
|
40 |
-
"This image likely belongs to {} with {:.2f}% confidence."
|
41 |
-
.format(name, 100 * numpy_array[i])
|
42 |
-
)
|
43 |
-
return "\n".join(output)
|
44 |
|
45 |
# describe the model
|
46 |
title = "Leaftracker Interactive Model"
|
@@ -54,7 +43,7 @@ description = """Leaftracker is an image classification model that differentiate
|
|
54 |
app = gr.Interface(
|
55 |
fn=predict_plant,
|
56 |
inputs=gr.Image(type="filepath"),
|
57 |
-
outputs=
|
58 |
flagging_options=["incorrect", "other"],
|
59 |
title=title,
|
60 |
description=description,
|
|
|
25 |
img_array = tf.keras.utils.img_to_array(img)
|
26 |
img_array = tf.expand_dims(img_array, 0)
|
27 |
|
28 |
+
# find the confidence probability for each plant
|
29 |
predictions = model.predict(img_array)
|
30 |
score = tf.nn.softmax(predictions[0])
|
31 |
+
confidences = {class_names[i]: float(score[i]) for i in range(len(class_names))}
|
32 |
+
return confidences
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# describe the model
|
35 |
title = "Leaftracker Interactive Model"
|
|
|
43 |
app = gr.Interface(
|
44 |
fn=predict_plant,
|
45 |
inputs=gr.Image(type="filepath"),
|
46 |
+
outputs=gr.Label(num_top_classes=3),
|
47 |
flagging_options=["incorrect", "other"],
|
48 |
title=title,
|
49 |
description=description,
|