MSK34's picture
Update src/streamlit_app.py
e5c05e0 verified
Raw
History Blame Contribute Delete
1.67 kB
import streamlit as st
import tensorflow as tf
import numpy as np
from PIL import Image
from tensorflow.keras.applications import MobileNetV2
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, GlobalAveragePooling2D, Rescaling
st.title("Üzüm Hastalığı Sınıflandırma - Transfer Learning")
# Colab'da kullandığımız MobileNetV2 taban modelini kuruyoruz.
base_model = MobileNetV2(
weights="imagenet",
include_top=False,
input_shape=(224, 224, 3)
)
base_model.trainable = False
tl_model = Sequential()
tl_model.add(Rescaling(1./255, input_shape=(224, 224, 3)))
tl_model.add(base_model)
tl_model.add(GlobalAveragePooling2D())
tl_model.add(Dense(128, activation="relu"))
tl_model.add(Dropout(0.3))
tl_model.add(Dense(4, activation="softmax"))
# Tam model yerine sadece ağırlıkları yüklüyoruz.
tl_model.load_weights("src/grape_transfer.weights.h5")
class_names = ['Black Rot', 'ESCA', 'Healthy', 'Leaf Blight']
uploaded_file = st.file_uploader(
"Bir üzüm yaprağı resmi yükleyin",
type=["jpg", "jpeg", "png"]
)
if uploaded_file is not None:
img = Image.open(uploaded_file).convert("RGB")
st.image(img, caption="Yüklenen Görsel", use_container_width=True)
img = img.resize((224, 224))
img_array = np.array(img)
img_array = np.expand_dims(img_array, axis=0)
prediction = tl_model.predict(img_array)
predicted_class = class_names[np.argmax(prediction)]
confidence = np.max(prediction) * 100
st.subheader("Tahmin Sonucu")
st.write("Sınıf:", predicted_class)
st.write("Güven Oranı:", round(confidence, 2), "%")