This project implements a feedforward neural network (FNN) from scratch using PyTorch to classify rice grains into two varieties — Jasmine and Gonen — based on morphological features extracted from grain images. The study demonstrates that lightweight neural network architectures can achieve high classification accuracy on well-structured agricultural datasets without the overhead of deep convolutional models.
Scope: This is a proof-of-concept implementation and learning exercise exploring the applicability of simple neural networks to agricultural grain classification tasks.
- Source:
riceClassification.csv— a tabular dataset of morphological measurements derived from rice grain images - Classes: Binary —
Jasmine (1)/Gonen (0) - Features (10 morphological attributes):
| Feature | Description |
|---|---|
| Area | Total pixel area of the grain |
| MajorAxisLength | Length of the major axis of the ellipse fitting the grain |
| MinorAxisLength | Length of the minor axis |
| Eccentricity | Eccentricity of the fitted ellipse |
| ConvexArea | Area of the convex hull of the grain |
| EquivDiameter | Diameter of a circle with the same area |
| Extent | Ratio of grain pixels to bounding box pixels |
| Perimeter | Grain boundary length |
| Roundness | Measure of circularity |
| AspectRation | Ratio of major to minor axis length |
- Preprocessing: Max-absolute normalization applied to all features;
idcolumn dropped; missing values removed
A simple feedforward neural network with the following structure:
Input Layer → (10 features)
Hidden Layer → Linear(10 → 20) + [implicit linear activation]
Output Layer → Linear(20 → 1) + Sigmoid
- Loss Function: Binary Cross-Entropy Loss (
BCELoss) - Optimizer: Adam (
lr = 0.01) - Batch Size: 32
- Epochs: 10
Note: No nonlinear activation (e.g., ReLU) is applied between the input and hidden layer in the current implementation, making the two linear layers effectively equivalent to a single linear transformation. This is a known architectural limitation and a potential area for improvement.
| Split | Proportion | Purpose |
|---|---|---|
| Training | 70% | Model training |
| Validation | 15% | Hyperparameter monitoring |
| Test | 15% | Final evaluation |
| Metric | Value |
|---|---|
| Final Training Accuracy | ~98.55% |
| Final Validation Accuracy | ~98.61% |
| Test Accuracy | 98.42% |
Training and validation loss converged steadily within 10 epochs, with no significant signs of overfitting.
This project is intentionally minimal and has the following known limitations:
- Binary classification only — does not generalize to multi-class rice variety identification
- Shallow architecture — a single hidden layer with no nonlinear activation between layers limits representational capacity
- Tabular features only — morphological CSV features are used rather than raw image data; a CNN-based approach on images would be more generalizable
- Small epoch count — 10 epochs may not represent fully converged training
- No regularization — dropout or L2 regularization not applied
Potential improvements:
- Add ReLU activation after the hidden layer
- Extend to multi-class classification (e.g., Arborio, Basmati, Ipsala, Karacadag)
- Implement a CNN pipeline operating directly on grain images
- Apply cross-validation for more robust evaluation
- Compare performance against traditional ML baselines (SVM, Random Forest)
torch
numpy
pandas
scikit-learn
matplotlib
torchsummary
Install with:
pip install torch numpy pandas scikit-learn matplotlib torchsummary- Clone the repository
- Place
riceClassification.csvin the project root - Open and run
rice_classification.ipynbsequentially
For inference on a new sample, update the morphological values in the prediction cell at the bottom of the notebook.
├── riceclassification.ipynb # Main notebook
├── riceClassification.csv # Dataset
└── README.md
This project was developed as part of an independent study in applied machine learning, focusing on agricultural classification tasks. The implementation prioritizes interpretability and simplicity over performance optimization, making it a useful reference for understanding neural network fundamentals in a real-world domain.
[Naosin Tabassum Lineya] [Jahangirnagar University] [lineyanaosin@gmail.com]