Utilizing a Convolutional-Neural-Network to perform image classification on fruits.
Report Bug
·
Request Feature
In this project, I've built a neural-network powered image classifier, that utilizes the users webcam to predict the type of fruit in the frame.
Of course this project doesn't have any real-world impact by itself. But similar machine-learning methods for image classification tasks are already revolutionizing fields with a much higher real-world impact like e.g. the classification of different cancer types or to make split-second decisions in the realm of autonomous driving.
The used dataset for training and validation has been manually shot and merged by my fellow data scientists Malte Bonart, Samuel McGuire and myself. It consists of 140 images of oranges, 91 images of apples and 46 images of bananas. I'm using a 80% training, 20% validation split. Even though it is a relative small and imbalanced dataset with only 277 images in total, the trained model performs quite well after training and achieves a validation accuracy in the high 90s.
The architecture of the neural-network I've chosen has 2,797,795 total trainable params. It is a CNN (Convolutional-Neural-Network) with multiple units comprised of 2D convolutional layer and MaxPooling2D layer with a pool size of (2, 2). After three of those units, the output is then flattened and put in a Dense layer, followed by a Dropout layer to aid with preventing overfitting, followed by another Dense layer. All hidden layers are utilizing a ReLU activation function, while the output-layer utilizes a Softmax activation function. As this is a multi-class classification task, I'm using the categorical_crossentropy loss function.
The model has been trained locally on a Macbook Pro 13-inch with a 2,3 GHz Quad-Core Intel Core i5.
Take a look at the neural-network architecture here:
I've also built an easy-to-use interface to test out the model utilizing your webcam. After following the instructions below, you can hold up an apple, banana or orange and after pressing 'p', the model will predict the fruit you're holding.
To get a local copy up and running follow these simple steps.
I'd advice you to create an own virtual environment for this project. I'm using Anaconda.
- Clone the repo
git clone https://github.com/dariustorabian/image-classifier.git- Install dependencies with the requirements.txt
conda create --name <NameOfEnvironment> --file requirements.txt-
Run capture.py in the command line and your webcam will open up. My pretrained model will automatically be loaded in. If you'd like to know how it was created, you can take a look at the code in the Jupyter Notebook model_selftrained.ipynb.
-
Press the
pkey while holding an apple, orange or banana to let the model tell you which fruit you are holding. PressSpaceto take a picture andqto close the window. Pictures will be saved in./out/if not specified otherwise per command-line argument while runingcapture.py.
Currently, there are no new features in planning. This could change though, so feel free to check back again.
You can also always take a look at the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Darius Torabian
- Feel free to contact me via mail.
- Here's my linkedin profile.
- My twitter-handle is:@darius_torabian.
- This is my website.
Project Link: https://github.com/dariustorabian/image-classifier
-
Netron - Great tool to visualize NN-architectures
-
OpenSansEmoji - Great font that is capable of displaying Emoji symbols.

