|
|
| import streamlit as st |
| import tensorflow as tf |
| import numpy as np |
| from PIL import Image |
|
|
| |
|
|
| model = tf.keras.models.Sequential([ |
| |
| tf.keras.layers.Conv2D(32, (3,3), activation="relu", input_shape=(128,128,3)), |
| tf.keras.layers.MaxPooling2D(2,2), |
|
|
| tf.keras.layers.Conv2D(64, (3,3), activation="relu"), |
| tf.keras.layers.MaxPooling2D(2,2), |
|
|
| tf.keras.layers.Conv2D(128, (3,3), activation="relu"), |
| tf.keras.layers.MaxPooling2D(2,2), |
|
|
| tf.keras.layers.Conv2D(256, (3,3), activation="relu"), |
| tf.keras.layers.MaxPooling2D(2,2), |
|
|
| tf.keras.layers.Conv2D(256, (3,3), activation="relu"), |
|
|
| tf.keras.layers.Flatten(), |
|
|
| 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_cnn.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("CNN 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((128,128)) |
|
|
| 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}") |