| import streamlit as st |
| import tensorflow as tf |
| import numpy as np |
| from PIL import Image |
|
|
| |
|
|
| base_model = tf.keras.applications.MobileNetV2( |
| weights="imagenet", |
| include_top=False, |
| input_shape=(224,224,3) |
| ) |
|
|
| base_model.trainable = False |
|
|
| model = tf.keras.models.Sequential([ |
| base_model, |
| tf.keras.layers.GlobalAveragePooling2D(), |
| tf.keras.layers.Dense(256, activation="relu"), |
| tf.keras.layers.Dropout(0.3), |
| tf.keras.layers.Dense(36, activation="softmax") |
| ]) |
|
|
| |
|
|
| model.load_weights("src/fruit_veg_transfer.weights.h5") |
|
|
| |
|
|
| class_names = [ |
| 'apple', 'banana', 'beetroot', 'bell pepper', 'cabbage', |
| 'capsicum', 'carrot', 'cauliflower', 'chilli pepper', |
| 'corn', 'cucumber', 'eggplant', 'garlic', 'ginger', |
| 'grapes', 'jalepeno', 'kiwi', 'lemon', 'lettuce', |
| 'mango', 'onion', 'orange', 'paprika', 'pear', |
| 'peas', 'pineapple', 'pomegranate', 'potato', |
| 'raddish', 'soy beans', 'spinach', 'sweetcorn', |
| 'sweetpotato', 'tomato', 'turnip', 'watermelon' |
| ] |
|
|
| st.title("Transfer Learning ile Meyve Sebze Sınıflandırma") |
|
|
| st.write("Bir meyve veya sebze görseli yükleyin.") |
|
|
| |
|
|
| uploaded_file = st.file_uploader( |
| "Bir görsel yükleyin", |
| type=["jpg", "jpeg", "png"] |
| ) |
|
|
| |
|
|
| if uploaded_file is not None: |
|
|
| image = Image.open(uploaded_file).convert("RGB") |
|
|
| st.image(image, caption="Yüklenen Görsel", use_container_width=True) |
|
|
| image = image.resize((224,224)) |
|
|
| image_array = np.array(image) / 255.0 |
|
|
| image_array = np.expand_dims(image_array, axis=0) |
|
|
| prediction = model.predict(image_array) |
|
|
| predicted_index = np.argmax(prediction) |
|
|
| predicted_class = class_names[predicted_index] |
|
|
| confidence = np.max(prediction) * 100 |
|
|
| st.success(f"Tahmin: {predicted_class}") |
|
|
| st.write(f"Güven Oranı: %{confidence:.2f}") |