Skip to content

Repository files navigation

Flower Classification

An end-to-end computer vision pipeline for 102-class flower recognition

Training, comparative evaluation, TensorFlow Lite optimization, and a deployable mobile model built with the Oxford 102 Flowers dataset.

Nine augmented Oxford flower images from the training generator

Project Overview

This repository presents a professional AI engineering workflow for multiclass image classification. It covers dataset integrity checks, class-aware splitting, augmentation, imbalance handling, transfer learning, CNN feature extraction for gradient-boosted trees, comparative evaluation, and TensorFlow Lite conversion.

MobileNetV2 achieved the strongest recorded test result and was selected as the deployable model artifact.

Project metric Recorded value
Flower classes 102
Source images 8,189
Images retained after duplicate handling 8,185
Models evaluated 4
Best test accuracy 95.71%
Optimized TensorFlow Lite size 2.53 MB

Key Capabilities

  • Validates image availability, readability, duplication, and class distribution.
  • Creates class-aware training, validation, and test splits.
  • Applies augmentation and balanced class weights for neural model training.
  • Compares XGBoost with CNN features, VGG16, NASNetMobile, and MobileNetV2.
  • Exports and evaluates an optimized TensorFlow Lite classifier.
  • Packages the final model and its 102-label mapping for mobile integration.

System Pipeline

Oxford 102 Flowers
        │
        ▼
Integrity checks ──► duplicate handling ──► class-aware split
        │
        ▼
Augmentation + [0, 1] scaling + class weighting
        │
        ├──► MobileNetV2 features + XGBoost
        ├──► VGG16
        ├──► NASNetMobile
        └──► MobileNetV2 ──► fine-tuning ──► TFLite optimization
                                                    │
                                                    ▼
                                      model + 102-class labels

Dataset

The pipeline uses the Oxford 102 Flowers dataset, containing 8,189 images across 102 flower categories. The official labels and split metadata are loaded, while this project creates a class-aware 60/10/30 split after duplicate handling.

Four duplicate groups were identified. One repeated image from each group was moved out of the training image pool, leaving 8,185 images:

Split Images Share of retained images
Training 4,872 59.52%
Validation 774 9.46%
Test 2,539 31.02%

Every class is represented in all three generated splits. Small differences from the target proportions result from integer rounding within each class.

Class distribution before splitting

Class counts before splitting show the dataset's substantial imbalance.

Class distribution across training, validation, and test splits

Class-aware allocation after duplicate handling.

The ten images in benchmark_images are unmodified samples from the Oxford dataset. Dataset downloads, extracted folders, and generated split folders are excluded from Git. Included dataset samples and all other third-party dataset content are not covered by the project's MIT License; see ATTRIBUTION.md.

Data Preparation

All neural models use 224 × 224 RGB inputs. Keras generators scale pixel values with rescale=1./255, producing the [0, 1] range for training, validation, testing, and TensorFlow Lite evaluation. The tracked TensorFlow Lite model expects the same input preprocessing.

Training augmentation includes:

  • rotations up to 15 degrees;
  • width and height shifts of 10%;
  • shear up to 10% and zoom up to 20%;
  • horizontal flips;
  • brightness scaling from 0.8 to 1.2;
  • nearest-neighbour fill for transformed pixels.

NumPy, TensorFlow, and generator seeds are set to 42. Balanced class weights are calculated from the training labels and supplied to neural model training.

Models Evaluated

XGBoost with CNN features

An ImageNet-pretrained MobileNetV2 backbone removes its classification head and produces fixed feature vectors through global-average pooling. RandomizedSearchCV evaluates three XGBoost configurations with two-fold cross-validation. The recorded best configuration uses 150 estimators, maximum depth 4, and learning rate 0.1.

VGG16

The ImageNet backbone begins frozen beneath global-average pooling and a 128-unit dense classifier. A second phase unfreezes the model and continues fine-tuning at a learning rate of 1e-5.

NASNetMobile

The pretrained backbone remains frozen beneath global-average pooling, a 256-unit dense layer, 50% dropout, and a 102-class softmax layer. The retained experiment is the base-training run because the attempted fine-tuning did not improve validation behaviour.

MobileNetV2

The pretrained backbone begins frozen beneath global-average pooling, 20% dropout, and a 102-class softmax layer. The selected model then undergoes full fine-tuning at 1e-5.

Training Strategy

The neural models use categorical cross-entropy, early stopping, learning-rate reduction where configured, augmentation, and class weighting. Accuracy plus macro and weighted precision, recall, and F1 are recorded. XGBoost uses multiclass log loss during fitting and the same classification metrics for evaluation.

MobileNetV2 base-training and fine-tuning accuracy and loss curves

Combined MobileNetV2 base-training and fine-tuning history. The dashed line marks the start of fine-tuning.

Results

The following results use the reserved test split of 2,539 images.

Model Test accuracy Weighted F1
XGBoost 79.80% 79.39%
VGG16 83.42% 83.41%
NASNetMobile 80.66% 80.50%
MobileNetV2 95.71% 95.72%
MobileNetV2 macro and weighted test metrics
Macro and weighted precision, recall, and F1 for the selected Keras model.

Model Comparison

Model Training time Inference per image Serialized size
XGBoost 483.13 s 0.000016 s 13.52 MB
VGG16 21,641.87 s 0.055700 s 169.40 MB
NASNetMobile 2,821.40 s 0.008552 s 22.30 MB
MobileNetV2 11,841.52 s 0.005182 s 27.74 MB

Training and inference times come from the recorded notebook run and are hardware-dependent. Model sizes are measurements of the serialized artifacts produced by that run.

Recorded quality, inference time, model size, and training time for four models

The original comparison uses logarithmic scaling because the recorded measures span different units and ranges.

TensorFlow Lite Conversion

The selected MobileNetV2 model is exported through SavedModel and converted with TensorFlow Lite default optimization.

Artifact Size
Keras MobileNetV2 27.74 MB
Optimized TensorFlow Lite 2.53 MB
Reduction 25.22 MB

The conversion notebook evaluates the optimized model on all 2,539 test images with the same [0, 1] input scaling used during neural-model training. Its displayed macro and weighted precision, recall, and F1 values round to 0.95.

TensorFlow Lite model test metrics

Android Application

The selected MobileNetV2 model was converted to TensorFlow Lite and integrated into FlowerApp on Google Play. The Android application is maintained separately: this repository contains the machine learning pipeline, final TensorFlow Lite artifact, and labels, but it does not include Android source code.

The related Google Play developer profile lists the published application.

Repository Structure

flower-classification/
├── assets/figures/
│   ├── dataset/                 # Dataset inspection figures
│   ├── evaluation/              # Model and TFLite evaluation figures
│   └── training/                # Learning curves
├── benchmark_images/            # Ten Oxford dataset samples
├── models/
│   ├── labels.txt               # Ordered 102-class mapping
│   └── mobilenetv2_optimized.tflite
├── notebooks/
│   ├── 01_flower_classification_training.ipynb
│   ├── 02_tflite_conversion_validation.ipynb
│   └── labels.txt               # Conversion-notebook label output
├── .gitignore
├── ATTRIBUTION.md
├── LICENSE
├── README.md
├── requirements-conversion.txt
└── requirements-training.txt

Raw data, generated splits, local Keras models, SavedModel exports, pickled predictions, and experiment-output directories remain local and are excluded from normal Git tracking.

Training Environment

notebooks/01_flower_classification_training.ipynb records Python 3.12.7, TensorFlow 2.19.0, NumPy 1.26.4, pandas 2.2.2, and scikit-learn 1.5.1. The remaining package pins in requirements-training.txt match the inspected local training environment.

python3.12 -m venv .venv-training
source .venv-training/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements-training.txt

Activate it later with:

source .venv-training/bin/activate

Conversion Environment

notebooks/02_tflite_conversion_validation.ipynb was intentionally developed in a separate environment. Its saved output records Python 3.10.18, TensorFlow 2.14.0, NumPy 1.23.5, pandas 2.3.1, and scikit-learn 1.7.1. Exact recorded core versions and bounded compatible notebook dependencies are defined in requirements-conversion.txt.

python3.10 -m venv .venv-conversion
source .venv-conversion/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements-conversion.txt

Activate it later with:

source .venv-conversion/bin/activate

Two environments are retained because the training and conversion runs were recorded with different Python, TensorFlow, NumPy, pandas, and scikit-learn versions. Combining them would misrepresent the environments that produced the saved results.

Installation

  1. Clone the repository.
  2. Create the training environment above.
  3. Download 102flowers.tgz, imagelabels.mat, and setid.mat from the official Oxford dataset page.
  4. Place those three files in a local raw_data/ directory at the repository root.

The downloaded archive and generated dataset folders are intentionally ignored by Git.

Usage

Run the notebooks in this order:

  1. Activate .venv-training and open notebooks/01_flower_classification_training.ipynb.
  2. Complete training and export the selected SavedModel locally.
  3. Deactivate the training environment.
  4. Activate .venv-conversion and open notebooks/02_tflite_conversion_validation.ipynb.
  5. Convert, validate, and package the TensorFlow Lite model.
source .venv-training/bin/activate
jupyter lab notebooks/01_flower_classification_training.ipynb

Then, in a separate conversion session:

source .venv-conversion/bin/activate
jupyter lab notebooks/02_tflite_conversion_validation.ipynb

Both notebooks locate the repository root automatically when launched from any directory inside the repository.

Reproducibility

  • NumPy, TensorFlow, and generator seeds are set to 42.
  • The two recorded software environments remain intentionally separate.
  • Dataset archives, split folders, and large generated models are reproducible local artifacts and are not committed.
  • Notebook outputs, execution counts, metrics, charts, and exported models are retained from the recorded runs.
  • The final label mapping contains 102 entries and is packaged with the TensorFlow Lite artifact.

Limitations

  • The dataset is imbalanced, and the custom split differs from the official Oxford split.
  • Timing measurements depend on the original hardware and software stack and should not be treated as device-independent benchmarks.
  • Neural models were trained and evaluated with pixel values scaled to [0, 1]. Architecture-specific preprocessing is a future experiment and is not claimed as part of the recorded results.
  • No per-class confusion matrix or systematic analysis of commonly confused categories is published.
  • The repository does not include the large Keras, SavedModel, serialized prediction, or Android source artifacts.

Future Improvements

  • Evaluate architecture-specific preprocessing in new controlled training runs.
  • Add per-class error analysis and confusion matrices without altering the recorded baseline.
  • Benchmark the TensorFlow Lite model across documented mobile hardware.
  • Add automated static validation for notebook syntax, artifact hashes, and model-interface compatibility.

Attribution

Dataset, pretrained-weight, architecture, and software references are listed in ATTRIBUTION.md. Third-party dataset content and pretrained weights are not covered by this repository's MIT License.

Licence

Project-authored source and documentation are available under the MIT License.

Contributors

This project was developed by Fatemeh Sabourinia and Alireza Zaeri.

About

Flower classification pipeline with comparative model evaluation and TensorFlow Lite deployment artifacts.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages