This project aims to classify 10 different types of fruits from images. By leveraging a deep learning model with transfer learning from a pre-trained convolutional neural network, MobileNetV2, the goal is to build an accurate image classification system that can distinguish between various fruit categories. This has applications in automated sorting, inventory management, and computer vision systems for retail.
- Dataset: Kaggle - Fruit Classification (10 class)
- Size: The dataset contains 10 classes of fruits. It is split into a training set of 1841 images, a validation set of 460 images, and a test set of 1025 images.
- Key Features: The raw fruit image data is used as input for the model.
- Approach:
- Data Preparation: The images were loaded and organized into training, validation, and test sets using
ImageDataGenerator. This approach automatically handles batching and resizing. - Data Augmentation:
ImageDataGeneratorwas used to augment the training data with transformations like rotation, shifting, and horizontal flips to increase the dataset's variability and prevent overfitting. - Transfer Learning: A pre-trained MobileNetV2 model, which was trained on a large image dataset (ImageNet), is used as a feature extractor. The base model's layers were frozen (
trainable=False). - Model Architecture: A custom deep learning model was built on top of the MobileNetV2 base, featuring
BatchNormalization,Dropoutlayers, andDenselayers for classification. The finalDenselayer has 10 units with asoftmaxactivation for multi-class classification. - Training: The model was compiled with the Adam optimizer and
categorical_crossentropyloss. It was trained for 80 epochs.
- Data Preparation: The images were loaded and organized into training, validation, and test sets using
- Best Accuracy:
- The model achieved a training accuracy of ~98.1% and a validation accuracy of 93.9% in the best epoch. The final evaluation on the validation set resulted in a loss of ~0.26 and an accuracy of 91.8%.
- Automated Fruit Sorting: Enables the automatic sorting of fruits in agricultural and food processing facilities.
- Quality Control: Assists in grading produce based on visual characteristics.
- Retail Management: Supports automated checkout systems and inventory management in grocery stores.
- Computer Vision: Provides a practical example of transfer learning for image classification tasks with a moderately sized dataset.
Clone the repository and extract the data from the zip file.
Install the necessary libraries:
pip install tensorflow keras pandas numpy seaborn matplotlib scikit-learnWe welcome contributions to improve the project. You can help by:
- Fine-tuning the hyperparameters of the custom head and training process to further optimize performance.
- Exploring different pre-trained models to compare their effectiveness.
- Implementing more robust data augmentation or preprocessing techniques.
- Adding a more detailed evaluation on the test set, including a classification report and confusion matrix, to validate the model's performance on unseen data.