File size: 2,807 Bytes
d6423a1
8a08d79
e6d4118
 
 
 
 
d6423a1
e6d4118
baec4bf
d6423a1
 
e6d4118
d6423a1
e6d4118
 
d6423a1
e6d4118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
title: FishClassifier_CNN_ResNet50
emoji: 🐠
colorFrom: blue
colorTo: green
sdk: streamlit
app_file: src/streamlit_app.py
pinned: false
short_description: CNN with ResNet50 for 9-class fish classification.
license: mit
---

# 🐟 Fish Species Classification – ResNet50 Transfer Learning

This project uses **Transfer Learning with ResNet50** to classify images of 9 different fish species.  
The model was trained using the **A Large Scale Fish Dataset** from Kaggle.

The goal of this project is to build a strong image classifier as part of my Deep Learning assignments.  
I also built a CNN model without transfer learning for comparison.

---

## πŸ“¦ Dataset

The dataset contains 9 fish classes:

- Black Sea Sprat  
- Gilt-Head Bream  
- Horse Mackerel  
- Red Mullet  
- Red Sea Bream  
- Sea Bass  
- Shrimp  
- Striped Red Mullet  
- Trout  

The dataset is balanced and includes several thousand images.

Source: https://www.kaggle.com/datasets/crowww/a-large-scale-fish-dataset

---

## 🧠 Model Overview (ResNet50)

This project uses **ResNet50 with ImageNet weights** as a feature extractor.

### Model pipeline:

1. Load ResNet50 without top layers (`include_top=False`)
2. Freeze all base layers
3. Add custom layers:
   - GlobalAveragePooling2D  
   - Dense(256, activation='relu')  
   - Dropout(0.5)  
   - Dense(9, activation='softmax')

### Training Settings

- Loss: `sparse_categorical_crossentropy`
- Optimizer: Adam (learning rate reduced automatically)
- Metrics:  
  - Accuracy  
  - Top-3 Accuracy  
- Callbacks:
  - EarlyStopping  
  - ReduceLROnPlateau  
  - ModelCheckpoint (saves the best model)

---

## πŸ“ˆ Model Performance

Results on validation data:

- **Validation Accuracy:** ~98.5%  
- **Top-3 Accuracy:** 100%  
- **Validation Loss:** ~0.05  

The ResNet50 model performs extremely well and clearly outperforms the CNN built from scratch.

---

## πŸš€ How to Use the Model

### Load model:
```python
import tensorflow as tf
model = tf.keras.models.load_model("best_fish_resnet50.keras")
Predict:
python
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)

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 prediction

View confidence scores for all 9 classes

πŸ“„ Project Files
File	Description
best_fish_resnet50.keras	Saved ResNet50 model
streamlit_app.py	Streamlit app code
requirements.txt	Required Python packages
ResNet50_Fish_Report.pdf	Technical report
fish_resnet50_history.pkl	Training history

## πŸ‘€ Author

**Enes Yamac**

Machine Learning & Computer Vision Project (2025)