Skip to content

Therm1te/AgriVision-CV

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AgriVision: Automated Multi-Class Fruit Classification 🍎🍌🥝

Python TensorFlow Transfer-Learning

AgriVision is an automated computer vision system designed for the agricultural industry and food supply chains. By leveraging Deep Transfer Learning, this system classifies 10 different types of fruits with high precision, enabling automated quality control and reducing manual sorting errors in food processing lines.

🚀 Project Overview

In modern food supply chains, automated quality control is essential to reduce waste and ensure safety. This project focuses on building a scalable, high-accuracy Computer Vision pipeline using the MobileNetV2 architecture to identify fruit varieties under varying conditions.

Key Features

  • 10-Class Classification: Apple, Avocado, Banana, Cherry, Kiwi, Mango, Orange, Pineapple, Strawberries, and Watermelon.
  • Transfer Learning: Utilizes pre-trained ImageNet weights for efficient feature extraction.
  • Two-Stage Training: Includes both Feature Extraction (frozen base) and Fine-Tuning (unfrozen top layers).
  • Robust Evaluation: Features Confusion Matrix analysis, Classification Reports, and Error Analysis.

📊 Dataset Details

The dataset was sourced from Roboflow.

  • Structure: Standardized train/, test/, and valid/ directories.
  • Preprocessing: Images resized to $224 \times 224$, normalized, and augmented with random rotations, shifts, and flips to prevent overfitting.

🛠️ Tech Stack

  • Language: Python
  • Framework: TensorFlow / Keras
  • Libraries: NumPy, Pandas, Matplotlib, Seaborn, Scikit-learn
  • Platform: Google Colab / Jupyter Notebooks

🏗️ Methodology

Phase 1: Data Exploration & Preprocessing

  • EDA: Visualized class distributions and sample images for each category.
  • Augmentation: Implemented ImageDataGenerator for real-time training augmentation (rotation, zoom, horizontal flip).

Phase 2: Model Development

  • Architecture: MobileNetV2 (chosen for its efficiency on mobile/edge devices).
  • Custom Head: Added Global Average Pooling, a Dense layer (128 units, ReLU), and Dropout (0.3).
  • Training: Compiled with Adam optimizer and Categorical Crossentropy loss.

Phase 3: Fine-Tuning

  • Unfroze the top 20 layers of the base model.
  • Re-trained with a very low learning rate ($1e-5$) to refine weights for specific fruit textures without destroying pre-trained features.

📈 Performance & Results

Final Test Accuracy: 86.27%

Metric Score
Precision (Weighted Avg) 0.87
Recall (Weighted Avg) 0.86
F1-Score (Weighted Avg) 0.86

Visualizations

Training Curves

Accuracy and Loss Plot

Confusion Matrix

Confusion Matrix

Error Analysis Insights

The model performed exceptionally well on unique textures (Avocados, Strawberries) but occasionally confused fruits with similar color profiles (Mango vs. Orange) or shared spherical geometry (Apple vs. Cherry).


💻 Usage

Inference

You can use the predict_fruit function to classify local images:

Predict a single image

class_name, confidence = predict_fruit('path/to/fruit_image.jpg') print(f"Predicted: {class_name} with {confidence*100:.2f}% confidence")


📝 Conclusion

AgriVision demonstrates that Transfer Learning is a powerful tool for niche agricultural tasks. The use of MobileNetV2 ensures that the model is not only accurate but also light enough for deployment in real-world sorting facilities.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Contributors