File size: 1,285 Bytes
647b0c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import streamlit as st
import tensorflow as tf
import numpy as np
from PIL import Image

# Uyarıları sustur
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

# Modeli yükle
model = tf.keras.models.load_model("mnist_augmented_model.keras")

st.title("🧠 MNIST Görüntü Artırma ve Tahmin")

uploaded_file = st.file_uploader("28x28 boyutunda bir el yazısı rakam görseli yükleyin", type=["png", "jpg", "jpeg"])

if uploaded_file is not None:
    image = Image.open(uploaded_file).convert("L").resize((28, 28))
    st.image(image, caption="Orijinal Görsel", width=150)

    img_array = np.array(image).astype("float32") / 255.0
    img_array = np.expand_dims(img_array, axis=-1)
    img_array = np.expand_dims(img_array, axis=0)

    def augment(image):
        image = tf.image.random_flip_left_right(image)
        image = tf.image.random_brightness(image, max_delta=0.1)
        image = tf.image.random_contrast(image, 0.8, 1.2)
        return image

    augmented = augment(tf.convert_to_tensor(img_array[0])).numpy()

    st.image([img_array[0].squeeze(), augmented.squeeze()], caption=["Orijinal", "Artırılmış"], width=150)

    prediction = model.predict(img_array)
    predicted_class = np.argmax(prediction)

    st.success(f"Modelin Tahmini: {predicted_class}")