|
import streamlit as st |
|
import tensorflow as tf |
|
import numpy as np |
|
from PIL import Image |
|
|
|
|
|
model_path = "flower-model-ResNet50.keras" |
|
model = tf.keras.models.load_model(model_path) |
|
|
|
|
|
def predict_flower(image): |
|
|
|
image = image.resize((150, 150)) |
|
image = image.convert('RGB') |
|
image = np.array(image) / 255.0 |
|
image = np.expand_dims(image, axis=0) |
|
|
|
|
|
prediction = model.predict(image) |
|
|
|
|
|
probabilities = tf.nn.softmax(prediction, axis=1) |
|
|
|
|
|
class_names = ['daisy', 'dandelion', 'rose', 'sunflower', 'tulip'] |
|
probabilities_dict = {flower_class: round(float(probability), 2) for flower_class, probability in zip(class_names, probabilities.numpy()[0])} |
|
|
|
return probabilities_dict |
|
|
|
|
|
st.title("Der Bluemenerkenner") |
|
st.write("Welche Blume wächst in ihrem Garten?") |
|
|
|
|
|
uploaded_image = st.file_uploader("Lade dein Bild hoch...", type=["jpg", "png"]) |
|
|
|
if uploaded_image is not None: |
|
image = Image.open(uploaded_image) |
|
st.image(image, caption='Hochgeladenes Bild.', use_column_width=True) |
|
st.write("") |
|
st.write("Identifizieren...") |
|
|
|
predictions = predict_flower(image) |
|
|
|
|
|
st.write("Vorhersagen für jede Klasse:") |
|
for flower_class, probability in predictions.items(): |
|
st.write(f"{flower_class}: {probability}") |
|
|
|
|
|
highest_probability_flower = max(predictions, key=predictions.get) |
|
|
|
|
|
|
|
st.write(f"Es ist eine: **{highest_probability_flower}**") |
|
|