Edit model card

Custom CNN Model for Fruit and Vegetable Disease Detection

Model Description

This model is a custom Convolutional Neural Network (CNN) designed to classify images of fruits and vegetables as either healthy or rotten. The model was built using Keras and trained on the Fruit and Vegetable Diseases Dataset, which contains high-quality images for machine learning in agriculture and food quality control.

Model Architecture

The model consists of the following layers:

  • Conv2D: 9 filters, kernel size (5, 5), padding 'same', input shape (128, 128, 3)
  • Activation: ReLU
  • MaxPooling2D: pool size (3, 3)
  • Conv2D: 64 filters, kernel size (5, 5), padding 'same'
  • Activation: ReLU
  • MaxPooling2D: pool size (2, 2)
  • Conv2D: 128 filters, kernel size (4, 4), padding 'same'
  • Activation: ReLU
  • MaxPooling2D: pool size (2, 2)
  • Conv2D: 128 filters, kernel size (3, 3), padding 'same'
  • Activation: ReLU
  • MaxPooling2D: pool size (2, 2)
  • Flatten
  • Dense: 512 units, activation ReLU
  • Dropout: rate 0.5
  • Dense: 64 units, activation ReLU
  • Dense: 28 units, activation Softmax (corresponding to the 28 classes of fruits and vegetables, healthy and rotten)

Training

The model was compiled and trained using the following settings:

  • Optimizer: Adam
  • Loss Function: Categorical Crossentropy
  • Metrics: Accuracy
  • Epochs: 10
  • Batch Size: 128

Training History

The training history includes metrics such as loss and accuracy for both training and validation datasets over 10 epochs. The training history is available as a JSON file and shows significant improvement in accuracy and reduction in loss over the epochs.

Example Training History

{
    "loss": [2.343, 1.384, 1.015, 0.761, 0.626, 0.517, 0.436, 0.374, 0.326, 0.285],
    "accuracy": [0.286, 0.582, 0.692, 0.764, 0.804, 0.839, 0.858, 0.878, 0.895, 0.907],
    "val_loss": [1.735, 1.201, 0.853, 0.639, 0.568, 0.504, 0.609, 0.451, 0.380, 0.387],
    "val_accuracy": [0.471, 0.637, 0.737, 0.805, 0.822, 0.843, 0.811, 0.869, 0.884, 0.885]
}

Dataset

The model was trained on the Fruit and Vegetable Diseases Dataset, which contains images categorized to assist in the development of machine learning models for detecting diseases in various fruits and vegetables.

Dataset Information

  • Number of Classes: 28 (Healthy and Rotten categories for 14 different fruits and vegetables)
  • Image Format: JPEG/PNG
  • Image Size: Varies (resized to 128x128 for this model)

Data Collection

This dataset has been compiled from various reputable sources, including Kaggle and GitHub repositories. Each image has been manually inspected and categorized to ensure high quality and relevance for the task of disease detection in fruits and vegetables.

Usage

The dataset is highly versatile and can be used for a variety of machine learning tasks, including:

  • Image Classification
  • Transfer Learning
  • Deep Learning

It is particularly useful for training models that can identify and distinguish between healthy and rotten produce, making it ideal for applications in agricultural technology and food quality control.

Preprocessing

Images were resized to a uniform size of 128x128 pixels to ensure consistent training. The dataset was split into training and validation sets to tune and evaluate the models effectively.

Model Performance

The model achieved the following performance metrics on the validation set after 10 epochs:

  • Validation Accuracy: 88.6%
  • Validation Loss: 0.388

Usage

To use this model, you can load it with Keras and use it to classify images of fruits and vegetables as either healthy or rotten.

from keras.models import load_model
import numpy as np
import cv2

# Load the model
model = load_model('custom_cnn_model.h5')

# Preprocess the image
image = cv2.imread('path_to_image')
image = cv2.resize(image, (128, 128))
image = np.expand_dims(image, axis=0)

# Predict the class
predictions = model.predict(image)
predicted_class = np.argmax(predictions, axis=1)
print(predicted_class)

Acknowledgements

This model and dataset were developed using resources from Kaggle and GitHub. Special thanks to Muhammad Subhan for compiling the Fruit and Vegetable Diseases Dataset.

License

This model and the associated dataset are available under the CC0: Public Domain license.

For more information, please refer to the dataset information PDF.

References

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Examples
Unable to determine this model's library. Check the docs .