Pirinc-Transfer-Learning / src /streamlit_app.py
MSK34's picture
Update src/streamlit_app.py
0449998 verified
Raw
History Blame Contribute Delete
1.61 kB
from tensorflow.keras.applications import VGG16
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Flatten, Dense
import streamlit as st
from PIL import Image
import numpy as np
base_model = VGG16(
weights="imagenet",
input_shape=(224,224,3),
include_top=False
)
for layer in base_model.layers:
layer.trainable = False
model = Sequential()
model.add(base_model)
model.add(Flatten())
model.add(Dense(1024, activation="relu"))
model.add(Dense(5, activation="softmax"))
# Şimdi eğitilmiş ağırlıkları yüklüyoruz
model.load_weights("/app/src/rice_transfer_model.weights.h5")
# sınıf isimlerini tanımlıyoruz
class_names = ["Arborio", "Basmati", "Ipsala", "Jasmine", "Karacadag"]
# resmi modele uygun hale getiriyoruz
def process_image(img):
img = img.resize((224,224))
img = np.array(img)
img = img / 255.0
img = np.expand_dims(img, axis=0)
return img
st.title("Transfer Learning Pirinç Siniflandirma")
st.write("Pirinç görseli yükle, model türünü tahmin etsin.")
# kullanıcıdan resim alıyoruz
file = st.file_uploader( "Bir resim yükle", type=["jpg","jpeg","png"])
# Şimdi tahmin yapıyoruz
if file is not None:
img = Image.open(file)
st.image(img, caption="Yüklenen Resim")
image = process_image(img)
prediction = model.predict(image)
predicted_class = np.argmax(prediction)
confidence = np.max(prediction) * 100
st.write(
"Tahmin:",
class_names[predicted_class]
)
st.write(
"Güven Oranı:",
round(confidence,2),
"%"
)