Classifying Healthy vs Rotten Fruits and Vegetables with Matrice
Dec 30, 2024
Ensuring the quality and safety of fruits and vegetables is essential for consumer health. With the rising interest in automating food inspection, computer vision offers an effective way to identify unhealthy produce. By training a model on images of fruits and vegetables, both healthy and rotten, we can enable quick, reliable classification that helps reduce waste and ensure quality.
In this project, we leverage computer vision and deep learning to classify fruits and vegetables as either healthy or rotten. Using a carefully curated dataset, our model will differentiate between healthy produce and those exhibiting signs of spoilage or disease. This classification can benefit various applications:
Automated Quality Control: Quickly identify spoiled produce in sorting lines to prevent them from reaching consumers.
Inventory Management: Alert systems for perishable stock, promoting timely processing and reduced waste.
Food Supply Chain Optimization: Enhance food safety standards and reduce economic losses by improving inventory selection.
In this blog, we’ll walk you through building this classification model using our no-code platform at Matrice. Key steps include:
Dataset Preparation
Model Training
Model Evaluation
Model Inference
Model Deployment
Dataset Preparation
The model is trained on the Fruit and Vegetable Diseases Dataset from Kaggle, containing images of both healthy and diseased produce across various types. This dataset is structured to allow deep learning models to effectively learn to distinguish between healthy and rotten produce for each type of fruit or vegetable.
Dataset Summary:
Total Classes: 28 (14 types of fruits and vegetables, with each type categorized as healthy or rotten)
Purpose: Enables the model to learn distinguishing features for identifying spoiled produce versus fresh, healthy options.
Data Splitting and Preparation
The data is split into training, testing, and validation sets using a 70:20:10
ratio to ensure robust model performance across unseen examples. This balanced approach helps the model generalize well when classifying images it hasn’t encountered during training.
Model Training
For this classification task, we experimented with several neural network architectures and configurations to optimize model performance. We tested multiple configurations to identify the best balance between accuracy and computational efficiency. The experiments included varying hyperparameters, such as batch size, epochs, and learning rate, to achieve the best results for the model’s classification capability.
Model Configurations:
Batch Size: 16
Epochs: 150
Learning Rate: 0.0001
Optimizer: AdamW
momentum: 0.95
Performance Metrics
The model’s classification performance was evaluated on both validation and test sets, yielding the following results:
Metric |
Value (test) |
Value (Val) |
---|---|---|
acc@1 |
0.984 |
0.981 |
Precision |
0.984 |
0.979 |
Recall |
0.983 |
0.977 |
Model Training Dashboard and Results
Category Performance:
This visualization provides insight into how the model performs across different categories, including both healthy and rotten classifications.
Training Loss Analysis:
The plot shows loss progression during training, highlighting stable convergence with well-tuned hyperparameters.
Model Testing
After training, our platform enables intuitive model testing. Simply upload an image, and the model generates a prediction, offering immediate feedback on classification accuracy.
Model Inference
Matrice’s platform supports exporting trained models in various formats (e.g., PyTorch, ONNX, TensorRT, and OpenVINO), enabling versatile deployment across devices. For scenarios like real-time quality control, the ONNX or OpenVINO formats optimize performance on resource-limited hardware.
Our platform’s export options provide users the flexibility to deploy models on specialized hardware or in cloud environments, enhancing adaptability across different operational needs.
Model Deployment
Matrice simplifies deployment, allowing users to seamlessly deploy trained models. After deployment, our platform’s servers manage all computations, making it easy to run inferences by uploading images and receiving predictions quickly.
We offer API integration across various languages (Python, JavaScript, PHP, Golang, etc.), facilitating smooth incorporation into web or mobile applications.
Conclusion
Classifying healthy vs. rotten produce with computer vision is an essential tool for quality control in the food industry. Matrice provides an accessible solution from dataset preparation to deployment, ensuring robust, real-time performance for quality control.
Our platform empowers you to make informed decisions on food quality, contributing to reduced waste and improved food safety.
Think CV, Think Matrice
Experience 40% faster deployment and slash development costs by 80%