Giter Club home page Giter Club logo

omndena-coffee-disease-classification-using-cnn's Introduction

omndena-coffee-disease-classification-using-CNN

CNN from scratch for image classification.

METRICS

Accuracy: 94.72%

Confusion Matrix: [[500 0 6 1 7] [ 0 501 0 0 0] [ 28 0 446 15 2] [ 11 0 36 406 28] [ 1 0 0 0 512]] F1 Score: 0.9452815737800676 Classification Report: precision recall f1-score support

       0       0.93      0.97      0.95       514
       1       1.00      1.00      1.00       501
       2       0.91      0.91      0.91       491
       3       0.96      0.84      0.90       481
       4       0.93      1.00      0.96       513

accuracy                           0.95      2500

macro avg 0.95 0.94 0.94 2500 weighted avg 0.95 0.95 0.95 2500

Libraries:

The code uses popular libraries like PyTorch, PIL, scikit-learn, matplotlib, and NumPy. Data Preparation: Data Augmentation and Transformation: Transformations like RandomResizedCrop, RandomHorizontalFlip, and normalization are defined to preprocess the images.

Load Data: A custom dataset class CoffeeLeafDataset is created to load images from a given folder and label them according to their sub-directory name. This custom dataset also filters out corrupted images.

Data Splitting: The dataset is split into training, validation, and test sets.

Data Loaders: PyTorch's DataLoader is used to create data loaders for training, validation, and test sets.

Model Architecture:

The model (CoffeeLeafClassifier) consists of:

Three convolutional layers followed by a ReLU activation and max-pooling. Three fully connected layers to reduce the dimensions and output class scores. Training: Device: Checks if a GPU is available and sets it as the device for computation.

Hyperparameters: Defines batch size, learning rate, and number of epochs.

Optimization and Loss: Uses Adam optimizer and Cross-Entropy Loss.

Training Loop: Trains the model and validates it after each epoch. Implements early stopping based on validation loss.

Metrics Evaluation:

Accuracy: Calculates the accuracy of the model on the test set.

F1 Score and Confusion Matrix: Uses scikit-learn to calculate the F1 Score and generate a confusion matrix.

Classification Report: Prints out a detailed classification report including precision, recall, and F1 score for each class.

Model Saving: The trained model is saved as a .pth file for future use.

Inference:

Class Mappings: Creates a mapping from class index to class names.

Single Image Prediction: Loads a sample image and runs it through the model to predict its class.

Batch Prediction and Visualization: Takes a batch of 15 images from the test set, predicts their classes, and visualizes them along with their actual and predicted labels using matplotlib.

omndena-coffee-disease-classification-using-cnn's People

Contributors

leulassaminew avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.