Added better bird classes and also the confidence score
Browse files
app.py
CHANGED
@@ -61,14 +61,18 @@ def classify_image(image):
|
|
61 |
classification = labels[predicted.item()]
|
62 |
|
63 |
# Check if the predicted class is a bird
|
64 |
-
|
65 |
-
is_bird = any(
|
|
|
|
|
|
|
|
|
66 |
|
67 |
if is_bird:
|
68 |
-
return f"This is a bird! Specifically, it looks like a {classification}."
|
69 |
else:
|
70 |
-
return f"This is not a bird. It appears to be a {classification}."
|
71 |
-
|
72 |
# Dynamically create the list of example images
|
73 |
example_files = sorted(glob.glob("examples/*.png"))
|
74 |
examples = [[file] for file in example_files]
|
|
|
61 |
classification = labels[predicted.item()]
|
62 |
|
63 |
# Check if the predicted class is a bird
|
64 |
+
bird_categories = ['bird', 'fowl', 'hen', 'cock', 'rooster', 'peacock', 'parrot', 'eagle', 'owl', 'penguin']
|
65 |
+
is_bird = ('bird' in classification.lower()) or any(category in classification.lower() for category in bird_categories)
|
66 |
+
|
67 |
+
# Get the confidence score
|
68 |
+
confidence_score = torch.nn.functional.softmax(output[0], dim=0)[predicted].item()
|
69 |
+
confidence_percentage = f"{confidence_score:.2%}"
|
70 |
|
71 |
if is_bird:
|
72 |
+
return f"This is a bird! Specifically, it looks like a {classification}. Model confidence: {confidence_percentage}"
|
73 |
else:
|
74 |
+
return f"This is not a bird. It appears to be a {classification}. Model confidence: {confidence_percentage}"
|
75 |
+
#
|
76 |
# Dynamically create the list of example images
|
77 |
example_files = sorted(glob.glob("examples/*.png"))
|
78 |
examples = [[file] for file in example_files]
|