A deep learning-based image classification system using Transfer Learning with MobileNetV2, achieving high accuracy (target: 95%+) for multi-class image classification tasks.
- Overview
- Features
- Dataset
- Model Architecture
- Installation
- Usage
- Training
- Evaluation
- Model Export
- Results
- Project Structure
- Contributing
- License
This project implements an end-to-end image classification pipeline using TensorFlow/Keras with Transfer Learning. The system leverages MobileNetV2 pre-trained on ImageNet for feature extraction and includes fine-tuning capabilities to achieve high accuracy on custom datasets.
Key Highlights:
- Transfer Learning with MobileNetV2
- Enhanced data preprocessing and augmentation
- Two-phase training (feature extraction + fine-tuning)
- Multiple export formats (H5, TFLite, TensorFlow.js)
- Comprehensive evaluation metrics
- Transfer Learning: Uses MobileNetV2 pre-trained weights for efficient training
- Data Augmentation: Advanced augmentation techniques to prevent overfitting
- Fine-Tuning: Optional fine-tuning phase for maximum accuracy
- Multi-Format Export:
- Keras H5 format
- TensorFlow Lite (mobile deployment)
- TensorFlow.js (web deployment)
- Comprehensive Metrics: Accuracy, confusion matrix, classification report
- Easy Inference: Simple API for making predictions on new images
The dataset should be organized in the following structure:
datasets/
βββ train_organized/
β βββ class1/
β β βββ image1.jpg
β β βββ image2.jpg
β β βββ ...
β βββ class2/
β βββ ...
βββ val_organized/
β βββ class1/
β βββ class2/
β βββ ...
βββ test_organized/
βββ class1/
βββ class2/
βββ ...
Dataset Split:
- Training: ~70-80%
- Validation: ~10-15%
- Testing: ~10-15%
The model uses MobileNetV2 as the backbone with a custom classification head:
Input (224x224x3)
β
MobileNetV2 Base (frozen initially)
β
GlobalAveragePooling2D
β
Dense(1024, relu)
β
Dropout(0.5)
β
Dense(num_classes, softmax)
Training Strategy:
- Phase 1: Train only the classification head (base frozen)
- Phase 2: Fine-tune the entire model with low learning rate
- Python 3.8+
- pip
-
Clone the repository
git clone https://github.com/yourusername/Klasifikasi-Gambar.git cd Klasifikasi-Gambar -
Create virtual environment
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies
pip install -r submission/requirements.txt
-
Start Jupyter
jupyter notebook
-
Open the notebook
- Navigate to
submission/notebook.ipynb - Run cells sequentially
- Navigate to
The notebook includes all steps:
- Data loading and preprocessing
- Model building
- Training (feature extraction)
- Fine-tuning
- Evaluation
- Model export
Key hyperparameters (can be modified in the notebook):
IMG_HEIGHT = 224
IMG_WIDTH = 224
BATCH_SIZE = 32
EPOCHS = 20 # Feature extraction phase
FINE_TUNE_EPOCHS = 10 # Fine-tuning phase-
Training: MobileNetV2 preprocessing + augmentation
- Rotation: Β±30Β°
- Width/Height shift: 20%
- Shear: 20%
- Zoom: 20%
- Horizontal flip
-
Validation/Test: MobileNetV2 preprocessing only
# Phase 1: Feature Extraction
history = model.fit(
train_generator,
epochs=EPOCHS,
validation_data=validation_generator,
callbacks=[EarlyStopping, ModelCheckpoint, ReduceLROnPlateau]
)
# Phase 2: Fine-Tuning
model.layers[0].trainable = True
model.compile(optimizer=Adam(lr=1e-5), ...)
history_finetune = model.fit(...)The model is evaluated using:
- Accuracy: Overall classification accuracy
- Confusion Matrix: Visual representation of predictions
- Classification Report: Precision, recall, F1-score per class
Example output:
Test Accuracy: 95.23%
Classification Report:
precision recall f1-score support
class1 0.96 0.94 0.95 150
class2 0.93 0.95 0.94 140
...
model.save('final_model.h5')converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
with open('model.tflite', 'wb') as f:
f.write(tflite_model)tensorflowjs_converter --input_format=keras final_model.h5 tfjs_model| Metric | Value |
|---|---|
| Training Accuracy | ~98% |
| Validation Accuracy | ~95% |
| Test Accuracy | 95%+ |
| Model Size (H5) | ~14 MB |
| Model Size (TFLite) | ~9 MB |
Note: Results may vary based on dataset and training configuration
Klasifikasi-Gambar/
βββ .venv/ # Virtual environment
βββ submission/
β βββ datasets/ # Dataset directory (not in git)
β β βββ train_organized/
β β βββ val_organized/
β β βββ test_organized/
β βββ notebook.ipynb # Main training notebook
β βββ requirements.txt # Python dependencies
β βββ best_model.h5 # Best model checkpoint
β βββ final_model.h5 # Final trained model
β βββ model.tflite # TFLite model
β βββ tfjs_model/ # TensorFlow.js model
β βββ PRD.md # Product requirements
βββ .gitignore
βββ README.md
- TensorFlow/Keras: Deep learning framework
- MobileNetV2: Pre-trained CNN architecture
- NumPy: Numerical computing
- Matplotlib/Seaborn: Visualization
- scikit-learn: Metrics and evaluation
- Jupyter: Interactive development
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.
Your Name
- GitHub: @yourusername
- Email: your.email@example.com
- MobileNetV2 architecture by Google
- TensorFlow/Keras team
- ImageNet dataset for pre-trained weights
For questions or issues, please:
- Open an issue on GitHub
- Contact: your.email@example.com
Note: Make sure to replace placeholder information (author details, repository URL) with your actual information before publishing.