Skip to content

soroushesnaashari/Rice-Images-Classification-with-CNN-using-PyTorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Rice Image Classification using CNN with PyTorch

Overview

This project implements a convolutional neural network (CNN) in PyTorch to classify images of rice. The goal is to develop a robust model capable of distinguishing between different varieties of rice, which can be useful for quality control, research or agricultural applications. The project covers all the steps—from data preprocessing and model design to training, evaluation and visualization of results.


Project Workflow

The project follows an end-to-end workflow:

  1. Data Acquisition & Preprocessing

    • Dataset Collection: Images of rice are gathered from available datasets or captured from the field.
    • Preprocessing: The images are resized, normalized, and augmented (if needed) to improve the robustness of the model.
    • Splitting: The dataset is divided into training, validation, and testing sets.
  2. Model Design & Implementation

    • CNN Architecture: A custom CNN is built using PyTorch. The model includes several convolutional and pooling layers to extract features, followed by fully connected layers for classification.
    • Compilation: The model is defined with a loss function (e.g., Cross-Entropy Loss) and an optimizer (e.g., Adam or SGD).
  3. Training & Evaluation

    • Training: The network is trained over multiple epochs. Training includes real-time monitoring of loss and accuracy on the validation set.
    • Evaluation: The trained model is evaluated on the test dataset. Metrics such as accuracy, precision, recall, and confusion matrices are used to assess performance.
    • Visualization: Training progress (loss and accuracy curves) and sample predictions are visualized to better understand the model's behavior.
  4. Results Analysis

    • Performance Metrics: Final results include overall accuracy, per-class performance, and error analysis to identify potential misclassifications.
    • Discussion: Observations on model strengths, weaknesses, and areas for future improvement are discussed.

Key Features

  • End-to-End Pipeline: The project handles all phases from data loading and preprocessing to model training and evaluation.
  • Custom CNN Architecture: A tailored CNN designed specifically for rice image classification, leveraging PyTorch's flexibility.
  • Data Augmentation: Techniques such as rotation, flipping, and scaling (if applied) to improve model generalization.
  • Performance Visualization: Graphs and plots that show training/validation loss and accuracy trends, along with sample predictions.
  • Modularity: Code structured into sections for ease of understanding, maintenance, and future enhancements.

Results

  • Model Accuracy: The CNN achieves high classification accuracy (e.g., over 99% on both models on the train set) in identifying rice types.
  • Training Curves: Loss and accuracy curves are provided to show convergence and detect any overfitting.
  • Error Analysis: A confusion matrix and sample misclassifications help pinpoint areas where the model might be improved.

Repository Contents

  • rice-classification-cnn-using-pytorch.ipynb: Jupyter Notebook with full code, visualizations and explanations.
  • Data: Contains the Original Dataset and you can see the cleaned dataset in notebook.
  • README.md: Project documentation.

How to Contribute

Contributions are welcome! If you'd like to improve the project or add new features:

  1. Fork the repository.
  2. Create a new branch.
  3. Make your changes and submit a pull request.

About

A CNN project using "PyTorch" to classify Rice images into five types

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published