metadata
language: en
license: apache-2.0
library_name: keras
tags:
- image-classification
- tensorflow
- efficientnet
- computer-vision
- cats-vs-dogs
metrics:
- accuracy
- auc
- precision
- recall
- f1
pipeline_tag: image-classification
Pet Classification with EfficientNetB0
This repository contains a high-performance deep learning model designed to classify images into two categories: Cats and Dogs. The model leverages the EfficientNetB0 architecture, utilizing Transfer Learning and specialized Fine-Tuning to achieve professional-grade metrics.
Model Performance
Evaluated on a balanced test set of 5,000 images, the model demonstrates exceptional stability and discriminative power:
| Metric | Score |
|---|---|
| Test Accuracy | 97.48% |
| AUC Score | 0.9974 |
| Precision | 96.77% |
| Recall | 0.9824 |
| F1-Score | 0.9750 |
Confusion Matrix Highlights
- Total Correct: 4,874 / 5,000 images.
- Sensitivity: High recall for 'Dog' class (0.9824), ensuring minimal false negatives.
- Confidence: Average Loss of 0.0651, indicating high certainty in classifications.
Architecture & Training Strategy
The model uses a multi-stage training pipeline to maximize the features learned from the ImageNet-pre-trained EfficientNetB0 base.
1. Model Structure
- Base: EfficientNetB0 (Functional)
- Pooling: GlobalAveragePooling2D
- Normalization: BatchNormalization for training stability.
- Dense Layers: 256 units (ReLU) followed by a 2-unit Softmax output.
- Regularization: Dropout (0.4) to ensure high generalization and prevent overfitting.
2. Training Phases
- Phase 1 (Transfer Learning): The base model was frozen, and only the custom classification head was trained (Learning Rate: 1e-3).
- Phase 2 (Fine-Tuning): The top 40 layers of the EfficientNet base were unfrozen and trained with a reduced learning rate (1e-4) to refine high-level feature detection.
How to Use
To use this model locally with the .keras file:
import tensorflow as tf
from tensorflow.keras.applications.efficientnet import preprocess_input
import cv2
import numpy as np
# Load model
model = tf.keras.models.load_model('efficientnetb0_pet_classifier_finetuned.keras')
def predict(img_path):
img = cv2.imread(img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (224, 224))
img = preprocess_input(np.expand_dims(img, axis=0))
preds = model.predict(img)
return "Dog" if np.argmax(preds) == 1 else "Cat"