--- title: FishClassifier_CNN emoji: 🐠 colorFrom: blue colorTo: green sdk: streamlit app_file: src/streamlit_app.py pinned: false short_description: CNN from scratch for 9-class fish classification. license: mit --- # 🐟 Fish Classification (CNN From Scratch) This project builds a **Convolutional Neural Network (CNN) from scratch** to classify images from the **"A Large Scale Fish Dataset"**, containing 9 different fish species. This model is part of a larger deep learning assignment where the goal is to build: 1. A CNN **without transfer learning** 2. A CNN **with transfer learning** (e.g., ResNet50) 3. A Streamlit app for each model 4. A technical PDF report for each dataset --- ## πŸ“‚ Dataset **A Large Scale Fish Dataset** Kaggle link: https://www.kaggle.com/datasets/crowww/a-large-scale-fish-dataset Dataset structure (after download): Fish_Dataset/ β”œβ”€β”€ Black Sea Sprat β”œβ”€β”€ Gilt-Head Bream β”œβ”€β”€ Horse Mackerel β”œβ”€β”€ Red Mullet β”œβ”€β”€ Red Sea Bream β”œβ”€β”€ Sea Bass β”œβ”€β”€ Shrimp β”œβ”€β”€ Striped Red Mullet └── Trout yaml Code kopieren --- ## 🧠 Model Overview The CNN was built using Keras Sequential API with: - **5 Convolutional Layers** - **3 MaxPooling Layers** - **1 Dense Layer (256 units)** - **Dropout (0.5)** - **Softmax output layer (9 classes)** **Training Setup:** - Loss: `sparse_categorical_crossentropy` - Optimizer: `Adam(lr=0.0005)` - Metrics: - `accuracy` - `top-3 accuracy` - Callbacks: - EarlyStopping - ModelCheckpoint (`best_fish_cnn.keras`) - ReduceLROnPlateau --- ## πŸ“ˆ Results Final model performance on validation data: - **Accuracy:** ~84% - **Top-3 Accuracy:** ~99% - **Validation Loss:** ~0.45 The model performed very well on distinct species (Shrimp, Red Mullet, Trout). Classes that look visually similar (Sea Bass, Bream types) caused some confusion. The technical report (PDF) contains: - Classification Report - Confusion Matrix - Full explanation of methods & reflection --- ## πŸš€ Usage ### How to Use the Model (CNN From Scratch) __Load the model__ import tensorflow as tf model = tf.keras.models.load_model("best_fish_cnn.keras") _Predict on a new image_ import numpy as np from tensorflow.keras.preprocessing import image img = image.load_img("your_image.jpg", target_size=(224, 224)) img_array = np.expand_dims(image.img_to_array(img), axis=0) / 255.0 # normalize pred = model.predict(img_array) print(pred) __Streamlit App__ This HuggingFace Space includes an interactive Streamlit app where you can: Upload a fish image See the model’s prediction View confidence scores for all 9 fish classes __Project Files__ File Description best_fish_cnn.keras Saved CNN model (from scratch, no transfer learning) streamlit_app.py Streamlit app code requirements.txt Required Python packages Fish_CNN_Report_English.pdf Technical report (simple English) ## πŸ‘€ Author **Enes Yamac** Machine Learning & Computer Vision Project (2025)