Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,20 +1,128 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
| 7 |
-
|
| 8 |
-
tags:
|
| 9 |
-
- streamlit
|
| 10 |
pinned: false
|
| 11 |
short_description: CNN from scratch for 9-class fish classification.
|
| 12 |
license: mit
|
| 13 |
---
|
| 14 |
|
| 15 |
-
#
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: FishClassifier_CNN
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
app_file: src/streamlit_app.py
|
|
|
|
|
|
|
| 8 |
pinned: false
|
| 9 |
short_description: CNN from scratch for 9-class fish classification.
|
| 10 |
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# π Fish Classification (CNN From Scratch)
|
| 14 |
|
| 15 |
+
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.
|
| 16 |
|
| 17 |
+
This model is part of a larger deep learning assignment where the goal is to build:
|
| 18 |
+
1. A CNN **without transfer learning**
|
| 19 |
+
2. A CNN **with transfer learning** (e.g., ResNet50)
|
| 20 |
+
3. A Streamlit app for each model
|
| 21 |
+
4. A technical PDF report for each dataset
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## π Dataset
|
| 26 |
+
**A Large Scale Fish Dataset**
|
| 27 |
+
Kaggle link: https://www.kaggle.com/datasets/crowww/a-large-scale-fish-dataset
|
| 28 |
+
|
| 29 |
+
Dataset structure (after download):
|
| 30 |
+
|
| 31 |
+
Fish_Dataset/
|
| 32 |
+
βββ Black Sea Sprat
|
| 33 |
+
βββ Gilt-Head Bream
|
| 34 |
+
βββ Horse Mackerel
|
| 35 |
+
βββ Red Mullet
|
| 36 |
+
βββ Red Sea Bream
|
| 37 |
+
βββ Sea Bass
|
| 38 |
+
βββ Shrimp
|
| 39 |
+
βββ Striped Red Mullet
|
| 40 |
+
βββ Trout
|
| 41 |
+
|
| 42 |
+
yaml
|
| 43 |
+
Code kopieren
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## π§ Model Overview
|
| 48 |
+
|
| 49 |
+
The CNN was built using Keras Sequential API with:
|
| 50 |
+
|
| 51 |
+
- **5 Convolutional Layers**
|
| 52 |
+
- **3 MaxPooling Layers**
|
| 53 |
+
- **1 Dense Layer (256 units)**
|
| 54 |
+
- **Dropout (0.5)**
|
| 55 |
+
- **Softmax output layer (9 classes)**
|
| 56 |
+
|
| 57 |
+
**Training Setup:**
|
| 58 |
+
|
| 59 |
+
- Loss: `sparse_categorical_crossentropy`
|
| 60 |
+
- Optimizer: `Adam(lr=0.0005)`
|
| 61 |
+
- Metrics:
|
| 62 |
+
- `accuracy`
|
| 63 |
+
- `top-3 accuracy`
|
| 64 |
+
- Callbacks:
|
| 65 |
+
- EarlyStopping
|
| 66 |
+
- ModelCheckpoint (`best_fish_cnn.keras`)
|
| 67 |
+
- ReduceLROnPlateau
|
| 68 |
+
|
| 69 |
+
---
|
| 70 |
+
|
| 71 |
+
## π Results
|
| 72 |
+
|
| 73 |
+
Final model performance on validation data:
|
| 74 |
+
|
| 75 |
+
- **Accuracy:** ~84%
|
| 76 |
+
- **Top-3 Accuracy:** ~99%
|
| 77 |
+
- **Validation Loss:** ~0.45
|
| 78 |
+
|
| 79 |
+
The model performed very well on distinct species (Shrimp, Red Mullet, Trout).
|
| 80 |
+
Classes that look visually similar (Sea Bass, Bream types) caused some confusion.
|
| 81 |
+
|
| 82 |
+
The technical report (PDF) contains:
|
| 83 |
+
- Classification Report
|
| 84 |
+
- Confusion Matrix
|
| 85 |
+
- Full explanation of methods & reflection
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## π Usage
|
| 90 |
+
|
| 91 |
+
### How to Use the Model (CNN From Scratch)
|
| 92 |
+
|
| 93 |
+
__Load the model__
|
| 94 |
+
|
| 95 |
+
import tensorflow as tf
|
| 96 |
+
|
| 97 |
+
model = tf.keras.models.load_model("best_fish_cnn.keras")
|
| 98 |
+
|
| 99 |
+
_Predict on a new image_
|
| 100 |
+
import numpy as np
|
| 101 |
+
from tensorflow.keras.preprocessing import image
|
| 102 |
+
|
| 103 |
+
img = image.load_img("your_image.jpg", target_size=(224, 224))
|
| 104 |
+
img_array = np.expand_dims(image.img_to_array(img), axis=0) / 255.0 # normalize
|
| 105 |
+
|
| 106 |
+
pred = model.predict(img_array)
|
| 107 |
+
print(pred)
|
| 108 |
+
|
| 109 |
+
__Streamlit App__
|
| 110 |
+
|
| 111 |
+
This HuggingFace Space includes an interactive Streamlit app where you can:
|
| 112 |
+
|
| 113 |
+
Upload a fish image
|
| 114 |
+
|
| 115 |
+
See the modelβs prediction
|
| 116 |
+
|
| 117 |
+
View confidence scores for all 9 fish classes
|
| 118 |
+
|
| 119 |
+
__Project Files__
|
| 120 |
+
File Description
|
| 121 |
+
best_fish_cnn.keras Saved CNN model (from scratch, no transfer learning)
|
| 122 |
+
streamlit_app.py Streamlit app code
|
| 123 |
+
requirements.txt Required Python packages
|
| 124 |
+
Fish_CNN_Report_English.pdf Technical report (simple English)
|
| 125 |
+
|
| 126 |
+
π Author
|
| 127 |
+
Enes Yamac
|
| 128 |
+
Deep Learning Portfolio Project (2025)
|