| import streamlit as st
|
| import tensorflow as tf
|
| import numpy as np
|
| import cv2
|
| from PIL import Image
|
| from tensorflow.keras.applications import MobileNetV2
|
| from tensorflow.keras.models import Sequential
|
| from tensorflow.keras.layers import GlobalAveragePooling2D, Dense, Dropout
|
|
|
|
|
| st.set_page_config(page_title="Fish Classifier / Balık Sınıflandırıcı", page_icon="🐟", layout="wide")
|
|
|
|
|
| @st.cache_resource
|
| def load_my_model():
|
|
|
| base_model = MobileNetV2(weights='imagenet', include_top=False, input_shape=(170, 170, 3))
|
| base_model.trainable = False
|
|
|
| model = Sequential([
|
| base_model,
|
| GlobalAveragePooling2D(),
|
| Dense(256, activation='relu'),
|
| Dropout(0.5),
|
| Dense(9, activation='softmax')
|
| ])
|
|
|
|
|
| try:
|
| model.load_weights('fish_transfer_model.h5')
|
| except:
|
| model = tf.keras.models.load_model('fish_transfer_model.h5')
|
| return model
|
|
|
| model = load_my_model()
|
|
|
|
|
| translate = {
|
| 'Black Sea Sprat': 'Karadeniz Çaça',
|
| 'Gilt-Head Bream': 'Çipura',
|
| 'Hourse Mackerel': 'İstavrit',
|
| 'Red Mullet': 'Barbun',
|
| 'Red Sea Bream': 'Mercan',
|
| 'Sea Bass': 'Levrek',
|
| 'Shrimp': 'Karides',
|
| 'Striped Red Mullet': 'Tekir',
|
| 'Trout': 'Alabalık'
|
| }
|
| class_labels = sorted(list(translate.keys()))
|
|
|
|
|
| with st.sidebar:
|
| st.title("🔍 Species List / Tür Listesi")
|
| st.write("Supported Fish Types / Desteklenen Balıklar:")
|
| for en, tr in translate.items():
|
| st.write(f"🔹 **{en}** / {tr}")
|
|
|
| st.markdown("---")
|
| st.info("Model: MobileNetV2\n\nAccuracy / Doğruluk: %99")
|
|
|
|
|
| st.title("🐟 Fish Classification System / Akıllı Balık Tanımlama")
|
| st.subheader("Deep Learning Project / Derin Öğrenme Projesi")
|
|
|
|
|
| main_container = st.container()
|
|
|
| with main_container:
|
| uploaded_file = st.file_uploader("Upload an image... / Bir resim yükleyin...", type=["jpg", "png", "jpeg"])
|
|
|
| if uploaded_file is not None:
|
| col1, col2 = st.columns([1, 1])
|
|
|
|
|
| image = Image.open(uploaded_file)
|
| col1.image(image, caption="Uploaded Image / Yüklenen Resim", use_container_width=True)
|
|
|
|
|
| with col2:
|
| st.write("### Analysis Result / Analiz Sonucu")
|
|
|
|
|
| img = np.array(image.convert('RGB'))
|
| img = cv2.resize(img, (170, 170))
|
| img = img / 255.0
|
| img = np.expand_dims(img, axis=0)
|
|
|
|
|
| preds = model.predict(img)
|
| idx = np.argmax(preds)
|
| prob = np.max(preds) * 100
|
|
|
| label_en = class_labels[idx]
|
| label_tr = translate[label_en]
|
|
|
|
|
| st.success(f"**Result / Sonuç:** {label_en} / {label_tr}")
|
| st.balloons()
|
|
|
| st.metric(label="Confidence / Güven Oranı", value=f"%{prob:.2f}")
|
|
|
|
|
| st.write("Probabilities / Olasılıklar:")
|
| chart_data = {f"{k} / {translate[k]}": float(preds[0][i]) for i, k in enumerate(class_labels)}
|
| st.bar_chart(chart_data)
|
|
|
|
|
| st.markdown("---")
|
| st.caption("Developed by Batman / Gotham City Data Labs 🦇") |