File size: 2,360 Bytes
70ba503
9db6eb4
3c27efc
70ba503
 
3c27efc
 
 
 
 
dc67056
80cbd93
fd05d61
80cbd93
 
fd05d61
 
 
8ec26eb
dc67056
 
8ec26eb
dc67056
8ec26eb
 
 
 
 
80cbd93
8ec26eb
dc67056
 
 
 
 
 
 
 
 
 
 
 
 
8ec26eb
 
dc67056
8ec26eb
 
dc67056
8ec26eb
 
dc67056
 
8ec26eb
 
dc67056
 
 
 
8ec26eb
 
 
 
 
dc67056
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import streamlit as st
from PIL import Image
import numpy as np
from tensorflow.keras.models import load_model

st.set_page_config(page_title="Sıtma Sınıflandırıcı", page_icon="🦟")

st.title("🦟 Sıtma Resmi Sınıflandırma")
st.write("Bir mikroskop görüntüsü yükleyin, sıtma olup olmadığını tahmin edelim.")

# MODEL YÜKLEME
model_path = "src/myn_cnn_model.h5"
try:
    model = load_model(model_path, compile=False)
    st.success(f"✅ Model yüklendi: `{model_path}`")
except Exception as e:
    st.error(f"❌ Model yüklenemedi: {e}")
    st.stop()

# SINIF ADLARI (Senin sıralamana göre değiştir)
class_names = ["Sıtma", "Sıtma Değil"]  # Eğer model ters sıralıysa değiştir

# RESİM YÜKLEYİCİ
file = st.file_uploader("📷 Mikroskop Görüntüsü Seçin", type=["jpg", "jpeg", "png"])

if file:
    try:
        image = Image.open(file).convert("RGB")
        st.image(image, caption="Yüklenen Görsel", use_container_width=True)

        # MODELİN INPUT BOYUTUNU AL
        input_shape = model.input_shape[1:3]  # Örneğin (170, 170)
        st.write(f"Modelin beklediği görsel boyutu: {input_shape}")

        # GÖRSELİ AYARLA
        img = image.resize(input_shape)
        img = np.array(img)

        if img.shape != (*input_shape, 3):
            st.error(f"Görsel boyutu beklenmeyen formatta: {img.shape}")
            st.stop()

        img = img / 255.0
        img = np.expand_dims(img, axis=0)

        # TAHMİN ET
        prediction = model.predict(img)

        # MODELİN SOFTMAX Mİ SİGMOID Mİ OLDUĞUNU ANLA
        if prediction.shape[-1] == 1:
            predicted_class = int(prediction[0][0] > 0.5)
            st.success(f"🧪 Tahmin: **{class_names[predicted_class]}**")
            st.write(f"Sıtma olasılığı: {prediction[0][0]:.4f}")
        elif prediction.shape[-1] == 2:
            predicted_class = int(np.argmax(prediction))
            st.success(f"🧪 Tahmin: **{class_names[predicted_class]}**")
            st.subheader("📈 Sınıf Skorları:")
            for i, score in enumerate(prediction[0]):
                st.write(f"{class_names[i]}: {score:.4f}")
        else:
            st.error("⚠️ Model çıktısı beklenmeyen formatta.")
            st.stop()

    except Exception as e:
        st.error(f"🚫 Görsel işleme veya tahmin hatası: {e}")