A deep learning project that classifies fish images into multiple species using CNN architectures and transfer learning. The project includes model training, comprehensive evaluation, and a user-friendly Streamlit web application for real-time predictions.
- Overview
- Features
- Models Implemented
- Dataset
- Project Structure
- Installation
- Usage
- Model Performance
- Technologies Used
- Results and Visualizations
- Contributing
- License
- Acknowledgments
This project addresses the challenge of automated fish species identification using computer vision and deep learning. The system:
- Trains 6 different models (1 custom CNN + 5 transfer learning models)
- Evaluates and compares their performance using multiple metrics
- Deploys the best model (MobileNet with 99.4% accuracy) in a Streamlit web app
- Provides real-time predictions with confidence scores
- Marine Biology Research: Automated species identification for biodiversity studies
- Fisheries Management: Quick identification for sustainable fishing practices
- Aquarium Management: Species verification and cataloging
- Educational Tools: Interactive learning platform for ichthyology students
- Multiple Model Architectures: Compare CNN from scratch with pre-trained models
- Comprehensive Data Augmentation: Rotation, zoom, flipping for robust training
- Detailed Evaluation Metrics: Accuracy, precision, recall, F1-score, confusion matrix
- Interactive Web App: Upload images and get instant predictions
- Model Comparison: Visual comparison of all models' performance
- Production-Ready: Saved models in
.h5and.kerasformats
| Model | Type | Test Accuracy | Parameters |
|---|---|---|---|
| Custom CNN | From Scratch | ~XX.X% | ~X.XM |
| VGG16 | Transfer Learning | ~XX.X% | ~XXM |
| ResNet50 | Transfer Learning | ~XX.X% | ~XXM |
| MobileNet | Transfer Learning | 99.4% β | ~X.XM |
| InceptionV3 | Transfer Learning | ~XX.X% | ~XXM |
| EfficientNetB0 | Transfer Learning | ~XX.X% | ~XXM |
Best Model: MobileNet achieved the highest accuracy and was selected for deployment.
The dataset consists of fish images organized into 11 species categories:
fish_data/
βββ train/ # Training images
β βββ species_1/
β βββ species_2/
β βββ ...
βββ val/ # Validation images
β βββ species_1/
β βββ species_2/
β βββ ...
βββ test/ # Test images
βββ species_1/
βββ species_2/
βββ ...
Data Preprocessing:
- Images resized to 224Γ224 pixels
- Normalized to [0, 1] range
- Augmentation: rotation (30Β°), zoom (0.2), horizontal/vertical flip
multiclass-fish-classification/
β
βββ MFC_test.ipynb # Complete training and evaluation notebook
βββ MFC_App.py # Streamlit web application
βββ class_labels.json # Fish species labels
β
βββ Custom CNN/
β βββ custom_cnn_model.h5
β βββ custom_cnn_model.keras
β
βββ VGG16/
β βββ vgg_finetuned_model.h5
β βββ vgg_finetuned_model.keras
β
βββ ResNet50/
β βββ resnet_finetuned_model.h5
β βββ resnet_finetuned_model.keras
β
βββ MobileNet/ # β Best Model
β βββ mobilenet_finetuned_model.h5
β βββ mobilenet_finetuned_model.keras
β
βββ InceptionV3/
β βββ inception_finetuned_model.h5
β βββ inception_finetuned_model.keras
β
βββ EfficientNetB0/
β βββ efficientnet_finetuned_model.h5
β βββ efficientnet_finetuned_model.keras
β
βββ requirements.txt
βββ README.md
Create a requirements.txt file with:
tensorflow>=2.10.0
streamlit>=1.25.0
pandas>=1.5.0
numpy>=1.23.0
matplotlib>=3.6.0
pillow>=9.3.0
scikit-learn>=1.2.0
-
Prepare your dataset: Organize images into
train/,val/, andtest/directories as shown in the Dataset section. -
Update data paths in the notebook:
train_dir = "path/to/your/fish_data/train"
val_dir = "path/to/your/fish_data/val"
test_dir = "path/to/your/fish_data/test"-
Run the training notebook:
- Open
MFC_test.ipynbin Jupyter Notebook or JupyterLab - Run all cells to train all 6 models
- Models will be saved automatically in their respective folders
- Open
-
Training parameters:
- Image size: 224Γ224
- Batch size: 32
- Custom CNN epochs: 20
- Transfer learning epochs: 5 (with fine-tuning)
- Ensure the MobileNet model is available:
# Check if the model file exists
ls MobileNet/mobilenet_finetuned_model.h5- Launch the application:
streamlit run MFC_App.py- Use the app:
- Open your browser at
http://localhost:8501 - Upload a fish image (JPG/PNG)
- View the prediction and confidence scores
- Explore top-3 predictions and raw probabilities
- Open your browser at
All models were evaluated on the test set using:
- Accuracy: Overall classification accuracy
- Precision: True positives / (True positives + False positives)
- Recall: True positives / (True positives + False negatives)
- F1-Score: Harmonic mean of precision and recall
- Confusion Matrix: Visual representation of classification performance
Custom CNN:
- Built from scratch with 3 convolutional blocks
- BatchNormalization for stable training
- Dropout (0.5) to prevent overfitting
- 20 epochs with Adam optimizer (lr=0.0001)
Transfer Learning Models:
- Initialized with ImageNet pre-trained weights
- Fine-tuned last layers (model-specific)
- GlobalAveragePooling2D for spatial dimension reduction
- Dense layers with Dropout (0.5)
- 5 epochs with Adam optimizer (lr=1e-5)
MobileNet was selected as the deployment model because:
- β Highest accuracy: 99.4% on test set
- β Lightweight: Small model size (~4MB)
- β Fast inference: Quick predictions for real-time use
- β Balanced performance: High precision and recall across all classes
- Deep Learning: TensorFlow, Keras
- Web Framework: Streamlit
- Data Processing: NumPy, Pandas
- Visualization: Matplotlib
- Model Evaluation: scikit-learn
- Image Processing: PIL (Pillow)
The training notebook generates:
- Accuracy/Loss Plots: Training and validation curves for each model
- Confusion Matrices: Per-model classification performance
- Classification Reports: Precision, recall, F1-score for each species
- Model Comparison Table: Side-by-side metrics comparison
Example visualizations are saved during training and can be reproduced by running the notebook.
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Dataset: https://drive.google.com/drive/folders/1iKdOs4slf3XvNWkeSfsszhPRggfJ2qEd
- Pre-trained Models: TensorFlow/Keras Applications
- Inspiration: Marine biology research and sustainable fishing practices
- Deep Learning and Neural Networks
- Transfer Learning and Fine-tuning
- Data Augmentation Techniques
- Model Evaluation and Comparison
- Web Application Deployment
- Python Programming (PEP 8 compliant)
- Git Version Control
β If you find this project helpful, please give it a star!