Skip to content

atiampa/Django-Classification-MachineLearning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

28 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ Banana Tester - AI-based Banana Ripeness Classification

Banner

This project demonstrates how to classify banana ripeness (unripe, ripe, overripe, rotten) using a deep learning model built on top of MobileNetV2. By applying data augmentation, splitting data into training, validation, and testing sets, and fine-tuning hyperparameters, the system achieves high accuracy in predicting the ripeness level of bananas.


๐Ÿ—‚๏ธ Data Preparation

  • ๐ŸŒ Data Source: Kaggle dataset and custom-collected images covering four ripeness categories.
  • ๐Ÿงน Data Cleaning: Organizing images into separate folders by ripeness level.
  • ๐Ÿ”„ Data Transformation: Standardizing image format (.JPG) for uniform processing.

โš™๏ธ Model Training

  • ๐Ÿค– MobileNetV2 Pre-trained on ImageNet, then fine-tuned for this specific 4-class classification.
  • ๐Ÿคธ Data Augmentation: Rotation, zoom, shifting, shearing, flipping for enhanced robustness.
  • ๐Ÿ“ˆ Hyperparameters: rotation_range=100, epochs=13, optimizer='adam', and more.

๐Ÿงช Model Testing

  • ๐ŸŽฏ Evaluation: Achieved up to 97.29% accuracy.
  • โฑ๏ธ Validation Loss Monitoring with EarlyStopping to avoid overfitting.

๐Ÿ’ก Model Improvement

  • ๐Ÿž Identified Deficiencies: Misclassification issues and version discrepancies (TensorFlow & Keras).
  • ๐Ÿ”ง Adjustments: Switching data sources, refining image resolutions, ensuring environment consistency.

โœจ Others (Optional)

  • โšก Potential Real-time Web Deployment for immediate ripeness detection and minimal human intervention.
  • ๐ŸŒ Further Extensions: Integration with IoT sensors (temperature/humidity) to predict optimal harvest windows.

๐Ÿงฐ Prerequisites

  • ๐Ÿ Python 3.x
  • ๐Ÿค– TensorFlow 2.x / Keras
  • ๐Ÿ— NumPy & Pandas for data handling
  • ๐Ÿ“Š Matplotlib & Seaborn for visualizations
  • ๐Ÿงช Sklearn for data splitting and performance metrics
  • ๐Ÿš€ GPU Support (optional but recommended for faster training)

๐ŸŒ 1. State the Problem

1.1 Problem and Pain Point

  • Currently, Thailand is experiencing a banana ๐ŸŒ shortage, leading to reduced banana production. Therefore, it is crucial to maximize the use of the limited banana supply. The โ€œBanana Testerโ€ ๐ŸŒ was created to evaluate the ripeness level of bananas, as relying solely on human visual inspection of peel color and softness can be highly uncertainโ€”subject to individual experience and environmental conditions. Moreover, fluctuating weather significantly affects the ripening rate, making it difficult to predict the ideal harvest time. Overripe or under-ripe bananas cannot be sold, resulting in economic losses, potential taste changes, and higher spoilage risks. Additionally, inconsistent ripeness levels among bananas increase labor and time spent sorting.

1.2 Related Work

  • Research References: Google Drive Link

  • Strengths and Weaknesses of Previous Research:
    From the studies reviewed, there are diverse methods of data collection, and the approaches for classifying banana ripeness are highly detailed. However, such methods can be time-consuming for data gathering. In contrast, our current experimental project involves faster data collection but still achieves comparable results.

  • Identified Gap:
    Existing research lacks a user-friendly program or website capable of real-time ๐ŸŒ analysis of banana ripeness. Addressing this gap is the key motivation for our systemโ€™s development.

1.3 Unique Method

  • Connecting Previous Research with Our Approach:
    Both the reviewed studies and our current project share a similar objectiveโ€”solving the uncertainty in human-based banana ๐ŸŒ ripeness classification. Such misclassification often leads to waste from prematurely rotten bananas. Therefore, the main aim of these studies and our project is to increase the accuracy of banana ripeness classification by leveraging AI ๐Ÿค–. Ultimately, this extends to creating a real-time web-based tool for easy and immediate use.

๐ŸŒ 2. Data Preparation

2.1 Data Source

2.2 Data Cleaning

  • Images are categorized into folders according to their ripeness level.

2.3 Data Transformation

  • All images used in this project are standardized to .JPG format. Each ripeness category is placed in its corresponding folder.

๐ŸŒ 3. Training

3.1 AI Model

  • Supervised Learning: Classification
    We employ a classification approach to distinguish between the four banana ripeness levels.

3.2 Hyperparameters

3.2.1 Data Augmentation Hyperparameters

  • rotation_range=100 โ†ช Randomly rotate images within ยฑ100 degrees
  • zoom_range=0.05 โ†ช Randomly zoom images up to 5%
  • width_shift_range=0.5 โ†ช Shift images horizontally by up to 50% of the width
  • height_shift_range=0.5 โ†ช Shift images vertically by up to 50% of the height
  • shear_range=0.15 โ†ช Apply shear transformations up to 15%
  • horizontal_flip=True โ†ช Enable horizontal flipping
  • fill_mode="nearest" โ†ช Fill in empty pixels using the nearest value

3.2.2 Data Splitting Hyperparameters

  • validation_split=0.2 โ†ช Reserve 20% of the data for validation; 80% is used for training
  • train_size=0.7 โ†ช 70% of the dataset is used for training, and 30% for testing

3.2.3 Model Architecture Hyperparameters

  • MobileNetV2 Pre-trained Model
    • input_shape=(224, 224, 3) โ†ช Input images have a resolution of 224ร—224ร—3
    • include_top=False โ†ช The final classification layers of MobileNetV2 are excluded
  • Dense Layers
    • 1 dense layer with 64 neurons, activation='relu'
    • 1 dense layer with 32 neurons, activation='relu'
    • Final dense layer with 4 neurons (activation='softmax') for the 4 classes
  • Dropout Layers
    • Dropout rate of 0.5 (50%) to help mitigate overfitting

3.2.4 Model Compilation Hyperparameters

  • optimizer='adam' โ†ช Use Adam optimizer to adjust model weights
  • loss='binary_crossentropy' โ†ช Use binary cross-entropy as the loss function

3.2.5 Model Training Hyperparameters

  • batch_size=32 โ†ช Number of examples processed in each weight update step
  • epochs=13 โ†ช Total number of training epochs
  • EarlyStopping
    • monitor='val_loss' โ†ช Monitor validation loss
    • patience=3 โ†ช Stop training if validation loss does not improve after 3 consecutive epochs
    • restore_best_weights=True โ†ช Revert to the best weights obtained during training

3.2.6 ImageDataGenerator Settings

  • shuffle=False โ†ช Disable shuffling of training samples (in certain generator setups)
  • seed=0 โ†ช Fix the random seed for reproducible results

3.3 Model Training

  • In this project, we use MobileNetV2 (pre-trained on ImageNet) and fine-tune it for banana ripeness classification. ๐ŸŒ

๐ŸŒ 4. Testing

4.1 Evaluation

accuracy

  • Accuracy: 97.29% ๐ŸŽ‰

4.2 Explanation of Results

  • After testing, our model achieved an accuracy of 97.29%. This score represents the proportion of correctly predicted outcomes compared to the total number of predictions, indicating high model performance. ๐Ÿš€

๐ŸŒ 5. Model Improvement

5.1 Model Deficiencies

  • Some instances were misclassified, with the model predicting the opposite class from reality. ๐Ÿ˜… This issue appeared during the initial training phase. Also, version discrepancies (e.g., TensorFlow 2.12.0 vs. 2.17.0, and Keras 3.6.0) contributed to training complications.

5.2 Model Adjustments

  • Increasing the image size (resolution) ๐Ÿ“ท for uploads can improve clarity and potentially reduce misclassification.

5.3 Re-Evaluation After Improvements

  • For the initial training, we used our own dataset, which introduced some uncertainty and lowered the modelโ€™s performance. We then switched to data from Kaggle, resulting in a significant improvementโ€”up to 97.29% accuracy. ๐Ÿคฉ

๐ŸŒ 6. Others (Optional)

This document consolidates the essential information regarding the Banana Tester ๐ŸŒ project. All references and data links are retained, and the text has been translated into English to provide broader accessibility.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors