Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,46 +22,19 @@ def predict_bmwX(image):
|
|
| 22 |
# Apply softmax to get probabilities for each class
|
| 23 |
prediction = tf.nn.softmax(prediction)
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
borderColie = np.round(float(prediction[0][4]), 2)
|
| 31 |
-
bostonTerrier = np.round(float(prediction[0][5]), 2)
|
| 32 |
-
chineseCrested = np.round(float(prediction[0][6]), 2)
|
| 33 |
-
cocker = np.round(float(prediction[0][7]), 2)
|
| 34 |
-
corgi = np.round(float(prediction[0][8]), 2)
|
| 35 |
-
dingo = np.round(float(prediction[0][9]), 2)
|
| 36 |
-
frenchBulldog = np.round(float(prediction[0][10]), 2)
|
| 37 |
-
germanShepard = np.round(float(prediction[0][11]), 2)
|
| 38 |
-
goldenRetriever = np.round(float(prediction[0][12]), 2)
|
| 39 |
-
pitBull = np.round(float(prediction[0][13]), 2)
|
| 40 |
-
rottweiler = np.round(float(prediction[0][14]), 2)
|
| 41 |
-
irishSpaniel = np.round(float(prediction[0][15]), 2)
|
| 42 |
-
labrador = np.round(float(prediction[0][16]), 2)
|
| 43 |
-
maltese = np.round(float(prediction[0][17]), 2)
|
| 44 |
-
newfoundland = np.round(float(prediction[0][18]), 2)
|
| 45 |
-
pomeranian = np.round(float(prediction[0][19]), 2)
|
| 46 |
-
poodle = np.round(float(prediction[0][20]), 2)
|
| 47 |
-
rhodesian = np.round(float(prediction[0][21]), 2)
|
| 48 |
-
saintBernard = np.round(float(prediction[0][22]), 2)
|
| 49 |
-
schnauzer = np.round(float(prediction[0][23]), 2)
|
| 50 |
-
scotchTerrier = np.round(float(prediction[0][24]), 2)
|
| 51 |
-
sharPei = np.round(float(prediction[0][25]), 2)
|
| 52 |
-
shibaInu = np.round(float(prediction[0][26]), 2)
|
| 53 |
-
siberianHusky = np.round(float(prediction[0][27]), 2)
|
| 54 |
-
yorkie = np.round(float(prediction[0][28]), 2)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
return
|
| 58 |
-
'Border Collie': borderColie, 'Boston Terrier': bostonTerrier, 'Chinese Crested': chineseCrested, 'Cocker': cocker,
|
| 59 |
-
'Corgi': corgi, 'Dingo': dingo, 'French Bulldog': frenchBulldog, 'German Shepard': germanShepard,
|
| 60 |
-
'GoldenRetriever': goldenRetriever, 'Pit Bull': pitBull, 'Rottweiler': rottweiler, 'Irish Spaniel': irishSpaniel,
|
| 61 |
-
'Labrador': labrador, 'Maltese': maltese, 'Newfoundland': newfoundland, 'Pomeranian': pomeranian,
|
| 62 |
-
'Poodle': poodle, 'Rhodesian': rhodesian, 'Saint Bernard': saintBernard, 'Schnauzer': schnauzer,
|
| 63 |
-
'Scotch Terrier': scotchTerrier, 'Shar Pei': sharPei, 'Shiba Inu': shibaInu, 'Siberian Husky': siberianHusky,
|
| 64 |
-
'Yorkie': yorkie}
|
| 65 |
|
| 66 |
|
| 67 |
input_image = gr.Image()
|
|
@@ -69,5 +42,5 @@ iface = gr.Interface(
|
|
| 69 |
fn=predict_bmwX,
|
| 70 |
inputs=input_image,
|
| 71 |
outputs=gr.Label(),
|
| 72 |
-
description="A simple
|
| 73 |
-
iface.launch(share=True)
|
|
|
|
| 22 |
# Apply softmax to get probabilities for each class
|
| 23 |
prediction = tf.nn.softmax(prediction)
|
| 24 |
|
| 25 |
+
# Define class names
|
| 26 |
+
class_names = ['Afghan', 'African Wild Dog', 'Beagle', 'Blenheim', 'Border Collie', 'Boston Terrier', 'Chinese Crested',
|
| 27 |
+
'Cocker', 'Corgi', 'Dingo', 'French Bulldog', 'German Shepard', 'Golden Retriever', 'Pit Bull',
|
| 28 |
+
'Rottweiler', 'Irish Spaniel', 'Labrador', 'Maltese', 'Newfoundland', 'Pomeranian', 'Poodle',
|
| 29 |
+
'Rhodesian', 'Saint Bernard', 'Schnauzer', 'Scotch Terrier', 'Shar Pei', 'Shiba Inu', 'Siberian Husky', 'Yorkie']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# Create a dictionary with the probabilities for each dog breed
|
| 32 |
+
prediction_dict = {class_names[i]: np.round(float(prediction[0][i]), 2) for i in range(len(class_names))}
|
| 33 |
+
|
| 34 |
+
# Sort the dictionary by value in descending order and get the top 3 classes
|
| 35 |
+
top_3 = dict(sorted(prediction_dict.items(), key=lambda item: item[1], reverse=True)[:3])
|
| 36 |
|
| 37 |
+
return top_3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
input_image = gr.Image()
|
|
|
|
| 42 |
fn=predict_bmwX,
|
| 43 |
inputs=input_image,
|
| 44 |
outputs=gr.Label(),
|
| 45 |
+
description="A simple MLP classification model for image classification using the MNIST dataset.")
|
| 46 |
+
iface.launch(share=True)
|