This project classifies different types of coffee roasts using a Convolutional Neural Network (CNN) implemented in TensorFlow and Keras.
The Coffee Roast Classifier is designed to automatically identify different roast levels in coffee beans using deep learning. It can classify beans into categories like light, medium, and dark roasts.
Dataset Source: Ontoum, S., Khemanantakul, T., Sroison, P., Triyason, T., & Watanapa, B. (2022). Coffee Roast Intelligence. arXiv preprint arXiv:2206.01841. Link to Dataset
- Number of classes: 4 (Dark, Green, Light, Medium)
- Total images: 1,200 (300 images per class in training set)
- Image dimensions: 50x50x3 (RGB)
Distribution per class:
- Dark Roast: 300 images
- Green Beans: 300 images
- Light Roast: 300 images
- Medium Roast: 300 images
The dataset is perfectly balanced with an equal number of images for each class, which is optimal for training the classification model.
data/
: Contains the dataset and preprocessing scriptsimages/
: Contains images for documentation and visualizationtraining_notebook.ipynb
: Main notebook containing the model training code
-
Input Layer
- Shape: (50, 50, 3) - RGB images
- Normalization: Input pixels scaled to [0, 1]
-
First Convolutional Block
- Conv2D: 32 filters, 3×3 kernel
- Batch Normalization
- ReLU Activation
- Max Pooling: 2×2 pool size
- L2 Regularization: l2_strength
-
Second Convolutional Block
- Conv2D: 64 filters, 3×3 kernel
- Batch Normalization
- ReLU Activation
- Max Pooling: 2×2 pool size
- L2 Regularization: l2_strength
-
Third Convolutional Block
- Conv2D: 64 filters, 3×3 kernel
- Batch Normalization
- ReLU Activation
- Max Pooling: 2×2 pool size
- L2 Regularization: l2_strength
- Dropout: 25%
-
First Dense Block
- Flatten Layer
- Dense: 128 units
- Batch Normalization
- ReLU Activation
- L2 Regularization: l2_strength
-
Second Dense Block
- Dense: 128 units
- Batch Normalization
- ReLU Activation
- L2 Regularization: l2_strength
-
Output Layer
- Dense: 4 units (one per class)
- Softmax Activation
-
Regularization Techniques:
- L2 Regularization on all Conv2D and Dense layers
- Batch Normalization after each major layer
- 25% Dropout after convolutional layers
-
Activation Functions:
- ReLU for intermediate layers
- Softmax for output layer
-
Parameters:
- Total params: [Add total params]
- Trainable params: [Add trainable params]
- Non-trainable params: [Add non-trainable params]
- Progressive increase in filters (32 → 64 → 64)
- Consistent 3×3 kernel size for all Conv2D layers
- Multiple batch normalization layers for stable training
- Dual 128-unit dense layers for feature extraction
Our CNN model achieved excellent performance in classifying coffee bean roast levels:
- Final Training Accuracy: 99.54%
- Final Validation Accuracy: 96.67%
- Early Stopping: Achieved at epoch 69
- Best Validation Loss: 0.1558
The model showed consistent improvement during training:
- Initial learning rate: 0.0005
- Implemented learning rate reduction on plateau
- Used early stopping to prevent overfitting
- Applied dropout (25%) and L2 regularization for better generalization
Training and validation metrics over epochs showing consistent improvement and good convergence
The model showed robust performance across all roast levels:
- Dark Roast: 98.5% accuracy
- Green (Unroasted): 100% accuracy
- Light Roast: 97.8% accuracy
- Medium Roast: 96.9% accuracy
Sample predictions showing correct classifications across different roast levels
- Balanced Performance: Maintained consistent accuracy across all classes
- Fast Convergence: Achieved optimal performance within 70 epochs
- Generalization: Model shows robust performance on unseen data
- Low False Positives: Minimal confusion between adjacent roast levels
- Successfully handles varying lighting conditions
- Effective with different bean orientations
- Reliable across different bean sizes
- Consistent performance with image augmentation
Confusion matrix showing the distribution of predictions across classes
The model demonstrates strong commercial viability with its high accuracy and reliable performance across all coffee bean roast categories.
- Python 3.x
- TensorFlow
- Keras
- OpenCV
- NumPy
- Matplotlib
- Scikit-learn
- Pandas
- Clone the repository:
git clone https://github.com/VijayendraDwari/roastcoffeeClassifier.git cd roastcoffeeClassifier