Skip to content

A simple Fruit Classification app built with Python, Tkinter, and KNN. The user selects an image, the model processes it, and predicts whether the fruit is an apple or a banana. Includes real-time image preview and a clean Tkinter GUI.

Notifications You must be signed in to change notification settings

Amir01m/Fruit-Classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍎 Fruit Classification

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.


πŸ“Œ How the Program Works

1️⃣ Dataset Preparation

The dataset is stored in the dataset/ folder. Images are:

  • Resized to 280x280 pixels
  • Flattened into a 1D array for the classifier

2️⃣ Feature and Label Extraction

The program separates features and labels:

  • x contains the image data
  • y contains the labels ("apple" or "banana")

3️⃣ Training the Classifier

The project uses KNeighborsClassifier from scikit-learn. Steps:

  • Split dataset into training and test sets (train_test_split)
  • Train the KNN model with xtrain and ytrain
  • Predict fruits for the test or user-provided images

4️⃣ User Interface (GUI)

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

5️⃣ How to Use

  1. Run gui.py with Python 3.x
  2. Click "Choose File" and select an image of apple or banana
  3. The program will display the predicted fruit in the label
  4. Click "Exit" to close the application

πŸ“ Requirements

Required Python libraries:

  • numpy
  • Pillow (PIL)
  • scikit-learn
  • tkinter (included in standard Python)

Install missing packages with pip:

pip install numpy pillow scikit-learn

β–Ά Running the Program

python gui.py

βœ” Project Structure

Fruit-Classification/
β”‚

β”œβ”€β”€ dataset/ β”‚ β”œβ”€β”€ apple/ β”‚ └── banana/ β”œβ”€β”€.gitignore β”œβ”€β”€ file_chooser.py β”œβ”€β”€ gui.py β”œβ”€β”€ model.py └── README.md


πŸ’‘ Notes

  • 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.

About

A simple Fruit Classification app built with Python, Tkinter, and KNN. The user selects an image, the model processes it, and predicts whether the fruit is an apple or a banana. Includes real-time image preview and a clean Tkinter GUI.

Topics

Resources

Stars

Watchers

Forks

Languages