This project is a simple fruit image classifier made with Python and Tkinter. It can identify apples and bananas from images. The user can choose an image, and the program predicts which fruit is in the image.
The dataset is stored in the dataset/ folder. Images are:
- Resized to 280x280 pixels
- Flattened into a 1D array for the classifier
The program separates features and labels:
xcontains the image dataycontains the labels ("apple" or "banana")
The project uses KNeighborsClassifier from scikit-learn. Steps:
- Split dataset into training and test sets (
train_test_split) - Train the KNN model with
xtrainandytrain - Predict fruits for the test or user-provided images
The program uses Tkinter GUI, which includes:
- A Choose File button to select an image
- A label showing the predicted fruit
- A canvas for possible future visualization
- An Exit button to close the program
- Run
gui.pywith Python 3.x - Click "Choose File" and select an image of apple or banana
- The program will display the predicted fruit in the label
- Click "Exit" to close the application
Required Python libraries:
numpyPillow (PIL)scikit-learntkinter(included in standard Python)
Install missing packages with pip:
pip install numpy pillow scikit-learn
python gui.py
Fruit-Classification/ ββββ dataset/ β βββ apple/ β βββ banana/ βββ.gitignore βββ file_chooser.py βββ gui.py βββ model.py βββ README.md
- Currently, only apples and bananas are supported.
- The model uses a small dataset, so predictions may not be accurate for unseen images.
- Images are resized and flattened for KNN input.