Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ def predict_flower(image):
|
|
12 |
# Preprocess image
|
13 |
image = image.resize((150, 150)) # Resize the image to 150x150
|
14 |
image = image.convert('RGB') # Ensure image has 3 channels
|
15 |
-
image = np.array(image)
|
16 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
17 |
|
18 |
# Predict
|
@@ -22,7 +22,7 @@ def predict_flower(image):
|
|
22 |
probabilities = tf.nn.softmax(prediction, axis=1)
|
23 |
|
24 |
# Map probabilities to Flower classes
|
25 |
-
class_names = ['daisy', 'dandelion', 'rose','sunflower','tulip']
|
26 |
probabilities_dict = {flower_class: round(float(probability), 2) for flower_class, probability in zip(class_names, probabilities.numpy()[0])}
|
27 |
|
28 |
return probabilities_dict
|
@@ -42,9 +42,14 @@ if uploaded_image is not None:
|
|
42 |
|
43 |
predictions = predict_flower(image)
|
44 |
|
|
|
|
|
|
|
|
|
|
|
45 |
# Find the flower with the highest probability
|
46 |
highest_probability_flower = max(predictions, key=predictions.get)
|
47 |
highest_probability_value = predictions[highest_probability_flower]
|
48 |
|
49 |
# Display the flower with the highest probability
|
50 |
-
st.write(f"Es ist eine: **{highest_probability_flower}** .")
|
|
|
12 |
# Preprocess image
|
13 |
image = image.resize((150, 150)) # Resize the image to 150x150
|
14 |
image = image.convert('RGB') # Ensure image has 3 channels
|
15 |
+
image = np.array(image) / 255.0 # Normalize the image to [0, 1]
|
16 |
image = np.expand_dims(image, axis=0) # Add batch dimension
|
17 |
|
18 |
# Predict
|
|
|
22 |
probabilities = tf.nn.softmax(prediction, axis=1)
|
23 |
|
24 |
# Map probabilities to Flower classes
|
25 |
+
class_names = ['daisy', 'dandelion', 'rose', 'sunflower', 'tulip']
|
26 |
probabilities_dict = {flower_class: round(float(probability), 2) for flower_class, probability in zip(class_names, probabilities.numpy()[0])}
|
27 |
|
28 |
return probabilities_dict
|
|
|
42 |
|
43 |
predictions = predict_flower(image)
|
44 |
|
45 |
+
# Log the predictions
|
46 |
+
st.write("Vorhersagen für jede Klasse:")
|
47 |
+
for flower_class, probability in predictions.items():
|
48 |
+
st.write(f"{flower_class}: {probability}")
|
49 |
+
|
50 |
# Find the flower with the highest probability
|
51 |
highest_probability_flower = max(predictions, key=predictions.get)
|
52 |
highest_probability_value = predictions[highest_probability_flower]
|
53 |
|
54 |
# Display the flower with the highest probability
|
55 |
+
st.write(f"Es ist eine: **{highest_probability_flower}** mit einer Wahrscheinlichkeit von {highest_probability_value} .")
|