All workCase 22 / 35

Fresh vs Rotten Apple Classifier

Image classifier deployed as a Streamlit app

TL;DR · Problem

The dataset is small by deep-learning standards: 5,031 images split into 4,024 for training, 127 for validation and 880 for testing.

TL;DR · Built

This is a group coursework project that classifies an apple photo as fresh or rotten.

TL;DR · Outcome

The app is live and the repository documents the dataset, environment, results and possible improvements such as EfficientNet and TensorFlow Lite.

Cover — Fresh vs Rotten Apple Classifier
Fresh vs Rotten Apple Classifier screenshot
01

Overview

This is a group coursework project that classifies an apple photo as fresh or rotten. The model is a MobileNetV2 network pretrained on ImageNet, trained in two phases with TensorFlow and Keras, and served through a Streamlit web app where anyone can upload an image.

I worked on it with eight classmates. My share was the project structure and dataset notes, the training notebook, and the Streamlit interface that loads the model, including a check that rejects images that are not apples.

02

The challenge

The dataset is small by deep-learning standards: 5,031 images split into 4,024 for training, 127 for validation and 880 for testing. Training from scratch would overfit, and no GPU was available locally, so a CPU epoch took about three minutes.

A public app has another problem. A classifier with two classes will label anything, so a photo of a car comes back as fresh or rotten.

03

The goal

Train an accurate classifier with limited data and hardware, and put it behind an interface people can try.

  • 01Use transfer learning from MobileNetV2 rather than training from scratch.
  • 02Evaluate on a held-out test set with a confusion matrix and learning curves.
  • 03Build a web app for uploading an image and seeing the prediction and confidence.
  • 04Reject inputs that do not look like the training data.
04

Training in two phases

The notebook first trains a new classification head with the MobileNetV2 base frozen, then unfreezes the top 30 layers and fine-tunes them. Early stopping restores the best weights, which matters because the validation set has only 127 images. The README reports 99.21% validation and 99.5% test accuracy after feature extraction, and 99.9% and 99.8% after fine-tuning. Training moved to a Colab T4 GPU, at about 10 seconds an epoch.

05

The Streamlit app

The app loads the saved Keras model, takes an uploaded image and shows the predicted class with a confidence bar. It has dark and light themes and is deployed on Streamlit Community Cloud.

06

Rejecting non-apple images

A helper module adds a two-layer out-of-distribution check. The first layer rejects predictions with low confidence. The second compares the image's MobileNetV2 features with statistics saved from the training set and rejects ones that are too far away.

Streamlit app
Non-apple image rejected
07

The outcome

The app is live and the repository documents the dataset, environment, results and possible improvements such as EfficientNet and TensorFlow Lite. The accuracy figures are the team's own reported results on this dataset, and the project mainly shows a full path from notebook to deployed model.

Work together

Have an idea worth building?

I take products from first sketch to shipped, on the web, on mobile and on-chain. Let's talk about yours.