A deep learning project to classify 8 types of green coffee bean defects using EfficientNetV2S and transfer learning, achieving high accuracy and precision.
- Developed a deep learning model using EfficientNetV2S with transfer learning to classify 8 types of green coffee bean defects.
- Applied advanced image augmentation techniques such as random rotation, translation, and contrast adjustment to enhance generalization and reduce overfitting.
Evaluates a pre-trained model on training and test datasets for green coffee bean defect classification and generates a confusion matrix (confusion_matrix.jpg
).
Creates augmented images (rotations) to improve model generalization and reduce overfitting.
Splits the dataset into stratified training and testing sets, organizing them into directories (coffee_bean_test
and coffee_bean_train
).
Trains a model using transfer learning with EfficientNetV2S and saves performance plots(accuracy.jpg
and loss.jpg
) and checkpoints(inside saved_models
).
Runs the full pipeline: dataset setup(unzipping downloaded .zip file), data augmentation, and training.
Cleans up generated files and directories, resetting the project environment.
The dataset used for this project is a modified version of the aggregation of the following datasets:
Tensorflow with GPU access is no longer supported past TensorFlow 2.10. Hence, it is recommended to use WSL2. The instructions below are from NVIDIA's setup docs for CUDA in WSL.
- Launch your preferred Windows Terminal/Command Prompt/Powershell and install WSL:
wsl --install
- Ensure you have the latest WSL kernel
wsl --update
- Setup your Linux user info by providing a username and password.
In the future, you can open WSL by typing
wsl
in the search bar in the Windows start menu.
- Remove the old GPG key:
sudo apt-key del 7fa2af80
- Run the installation instructions one by one as indicated on the CUDA download page for WSL-Ubuntu
NOTE: It is important to check if your system meets the hardware, software, and system requirements to run TensorFlow. Please check in the official TensorFlow documentation for more details.
- Clone the repository
git clone https://github.com/pierre-parel/cbd.git
cd cbd
- Create virtual environment and install required modules
sudo apt install python3 python3-venv
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
- Download
dataset.zip
and place it in the root folder. - Unzip the dataset, generate train/test split, and train the model using
run.sh
:
./run.sh
- To evaluate the model, modify line 8 of
evaluate.py
to the desired saved model and run:
python evaluate.py
- Use GPU for faster training. See Install TensorFlow with pip and Use a GPU
- Change from Xception to EfficientNetV2B0.
- Use different pretrained model for comparison
- Data augmentation
- Prefetch dataset
- Test multilabel classification
- Fine-tuning of the model
- Experiment with different layers in my_model
- Try using other image augmentation techniques
- Image Classification from Scratch
- EfficientNetV2B0 function
- Load image dataset from directory
- Image classification via fine-tuning with EfficientNet
- Transfer learning & fine tuning
- Losses
- The Deeplearning Book
- Convolution Neural Networks Course by Andrew Ng
- Deep Learning by 3Blue1Brown
- Understanding Deep Learning Book
- The Principles of Deep Learning Theory
- How to Predict New Samples With Your Keras Model