Welcome to the Fruit Detector project! This repository contains a machine learning model that can identify different fruits from images. π₯π
Here's an overview of the project directory:
C:\Users\Arman\Desktop\ML\Projects\Fruit-Detector
β
βββ Test_File/
β βββ [Test images...]
βββ Train_File/
β βββ [Training images...]
β
βββ Fruit_Detector.py
βββ fruit_detector_model.h5
βββ label_encoder.npy
βββ predict_fruit.py
Make sure you have the following installed:
- Python 3.x
- Necessary Python packages (use
pip install -r requirements.txt
)
Clone the repository:
git clone https://github.com/your-username/fruit-detector.git
cd fruit-detector
To train the model, run the Fruit_Detector.py
script:
python Fruit_Detector.py
This will load images from the Train_File
directory, train the model, and save it as fruit_detector_model.h5
. It also saves the label encoder as label_encoder.npy
.
To predict the fruit in an image, use the predict_fruit.py
script:
python predict_fruit.py <path_to_image>
Replace <path_to_image>
with the path to your image file. For example:
python predict_fruit.py ./Test_File/apple_01.jpg
This script handles the entire pipeline from loading data, training the model, and saving the model and label encoder. Key steps include:
- Loading Images: Reads images and their labels from the
Train_File
andTest_File
directories. - Preprocessing: Normalizes the images and encodes the labels.
- Model Building: Constructs a Convolutional Neural Network (CNN) using Keras.
- Training: Trains the model on the training data and evaluates it on the test data.
- Saving: Saves the trained model and label encoder for later use.
This script loads a saved model and label encoder to make predictions on new images. Key steps include:
- Loading Model: Loads the trained model and label encoder.
- Image Preprocessing: Prepares the image for prediction by resizing and normalizing.
- Prediction: Predicts the class of the fruit and prints the result with confidence score.
After training, the model achieved an accuracy of 97.27% on the test data.
- Expand the dataset with more fruit images.
- Improve the model architecture for better accuracy.
- Implement data augmentation to enhance model robustness.
Contributions are welcome! Feel free to open issues or submit pull requests.
For questions or comments, please reach out to [email protected].
Happy Coding! π