Automating visual inspection with ML in Agriculture
This repository contains a machine learning model for classifying lemon quality based on images. The model is built using various image processing techniques and machine learning classifiers. The dataset used consists of images of lemons, which are categorized into four classes:
- Excellent
- Good
- Processed Products
- Disqualified
The repository provides code for loading and processing the dataset, extracting features from images, training multiple classifiers, and evaluating their performance.
To run this project, you'll need to install the required dependencies. You can install them using the provided requirements.txt
:
pip install -r requirements.txt
lemon_classification.py
: The main script for loading data, training classifiers, and evaluating their performance.requirements.txt
: A list of Python dependencies required to run the project.README.md
: This file, describing the project and its setup.
The dataset used in this project contains images of lemons. The dataset is divided into two parts:
- Training Images: Used to train the models.
- Test Images: Used to evaluate the model's performance.
The dataset can be downloaded and extracted using the skillsnetwork
library. To prepare the data, the following code is used:
await skillsnetwork.prepare("https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-GPXX0UEREN/hiroshima-lemon.zip", overwrite=True)
The features are extracted using Haralick texture features, which capture the structural properties of the images. These features are then used to train the machine learning classifiers.
The following classifiers are trained and evaluated:
- Logistic Regression
- K-Nearest Neighbors (KNN)
- Support Vector Classifiers (SVC) with linear and RBF kernels
- Gaussian Process Classifier
- Decision Tree Classifier
- Random Forest Classifier
- Neural Network (MLPClassifier)
- AdaBoost Classifier
- Naive Bayes Classifier
- Quadratic Discriminant Analysis (QDA)
The models are evaluated based on their accuracy on the training and validation datasets. A confusion matrix is also generated for each classifier to visualize its performance.
After training the classifiers, the results (including predictions on the test set) are saved in a CSV file. The classification results are also visualized by displaying a few test images along with their predicted class.
-
Clone this repository:
git clone https://github.com/your-username/lemon-classification.git cd lemon-classification
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the script:
script.ipynb
This will train the models, evaluate them, and save the test results in results.csv
.
This project is licensed under the MIT License - see the LICENSE file for details.