ESMATUGBA commited on
Commit
de1987e
·
verified ·
1 Parent(s): 49b05e3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +82 -0
  2. cnn_model.h5 +3 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import cv2
4
+ from tensorflow.keras.models import load_model
5
+
6
+ # 1. Page Configuration / Sayfa Ayarları (Centered layout seçildi)
7
+ st.set_page_config(page_title="CNN Boundary Detector", layout="centered")
8
+
9
+ # Sabitleme ve Titremeyi Önleme için CSS
10
+ st.markdown("""
11
+ <style>
12
+ .stImage > img {
13
+ border-radius: 8px;
14
+ border: 1px solid #ddd;
15
+ }
16
+ /* Sütunlar arasındaki boşluğu ve hizalamayı koru */
17
+ [data-testid="stHorizontalBlock"] {
18
+ align-items: center;
19
+ }
20
+ </style>
21
+ """, unsafe_allow_html=True)
22
+
23
+ @st.cache_resource
24
+ def load_my_model():
25
+ # Model ismini kendi dosya isminle değiştir (.h5 veya .keras)
26
+ return load_model("cnn_segmentation_model.keras", compile=False)
27
+
28
+ model = load_my_model()
29
+
30
+ # Header / Başlık (Ortalı)
31
+ st.markdown("<h1 style='text-align: center;'>🎯 Boundary Detection System</h1>", unsafe_allow_html=True)
32
+ st.markdown("<h3 style='text-align: center; color: gray;'>Kenar ve Sınır Tespit Sistemi</h3>", unsafe_allow_html=True)
33
+ st.write("---")
34
+
35
+ # 2. Upload Section / Yükleme Bölümü
36
+ uploaded_file = st.file_uploader("Upload Image / Resim Yükleyin", type=["jpg", "jpeg", "png"])
37
+
38
+ if uploaded_file is not None:
39
+ # Görüntü İşleme
40
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
41
+ img = cv2.imdecode(file_bytes, 1)
42
+ img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
43
+
44
+ # Model Tahmini (168x168)
45
+ img_input = cv2.resize(img_rgb, (168, 168)) / 255.0
46
+ img_input = np.expand_dims(img_input, axis=0)
47
+
48
+ with st.spinner('Analyzing... / Analiz ediliyor...'):
49
+ pred = model.predict(img_input, verbose=0)[0]
50
+ mask = pred.squeeze()
51
+
52
+ # Notebook stili parlatma (Normalization)
53
+ mask_norm = (mask - mask.min()) / (mask.max() - mask.min() + 1e-7)
54
+ mask_255 = (mask_norm * 255).astype(np.uint8)
55
+
56
+ # Orijinal boyuta geri getir
57
+ mask_resized = cv2.resize(mask_255, (img_rgb.shape[1], img_rgb.shape[0]))
58
+
59
+ # Overlay (Yeşil Kenar)
60
+ overlay = img_rgb.copy()
61
+ # Eşik (Threshold) 120 olarak ayarlandı
62
+ overlay[mask_resized > 120] = [0, 255, 0]
63
+ final_blend = cv2.addWeighted(img_rgb, 0.7, overlay, 0.3, 0)
64
+
65
+ # 3. YAN YANA VE ORTALANMIŞ GÖSTERİM
66
+ col1, col2 = st.columns(2)
67
+
68
+ with col1:
69
+ st.markdown("<p style='text-align: center; font-weight: bold;'>Original / Orijinal</p>", unsafe_allow_html=True)
70
+ st.image(img_rgb, use_container_width=True)
71
+
72
+ with col2:
73
+ st.markdown("<p style='text-align: center; font-weight: bold;'>Prediction / Tahmin</p>", unsafe_allow_html=True)
74
+ st.image(final_blend, use_container_width=True)
75
+
76
+ # Opsiyonel: Siyah Beyaz Maske
77
+ st.write("---")
78
+ with st.expander("Show Binary Mask / İkili Maskeyi Göster"):
79
+ st.image(mask_resized, width=400, caption="Grayscale Output")
80
+
81
+ else:
82
+ st.info("Waiting for image upload... / Resim yüklenmesi bekleniyor...")
cnn_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:304a702b1203a244e7d991399c6c5bac3017d62974a969c5172464ac0d8f6659
3
+ size 9381688