File size: 1,214 Bytes
55355a1
 
5b35af8
55355a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b35af8
55355a1
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
# Fashion MNIST CNN modeli ile kıyafet sınıflandırma uygulaması oluşturuyoruz.

import streamlit as st
import tensorflow as tf
import numpy as np
from PIL import Image


st.title("Fashion MNIST Image Classification")

st.write(
    "Bu uygulama, yüklenen kıyafet görselini CNN modeli ile sınıflandırır."
)


# Eğitilmiş modeli yüklüyoruz.

model = tf.keras.models.load_model("src/fashion_mnist_cnn.h5")


# Sınıf isimlerini tanımlıyoruz.

class_names = [
    "T-shirt",
    "Trouser",
    "Pullover",
    "Dress",
    "Coat",
    "Sandal",
    "Shirt",
    "Sneaker",
    "Bag",
    "Ankle Boot"
]



# Kullanıcıdan görsel alıyoruz.

uploaded_file = st.file_uploader(
    "Bir kıyafet görseli yükleyin",
    type=["png", "jpg", "jpeg"]
)


if uploaded_file is not None:

    img = Image.open(uploaded_file).convert("L")

    st.image(img, caption="Yüklenen Görsel", width=300)

    img = img.resize((28, 28))

    img_array = np.array(img)

    img_array = img_array / 255.0

    img_array = img_array.reshape(1, 28, 28, 1)

    prediction = model.predict(img_array)

    class_index = np.argmax(prediction)

    st.subheader("Tahmin Sonucu")

    st.success(class_names[class_index])