Skip to content

About

A TensorFlow/Keras image classifier that trains a custom ResNet-style convolutional neural network to classify flower images from the Oxford Flowers 102 dataset (102 flower categories)

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Flower Image Classifier

Python TensorFlow Keras TensorFlow Datasets

A TensorFlow/Keras image classifier that trains a custom ResNet-style convolutional neural network to classify flower images from the Oxford Flowers 102 dataset (102 flower categories).

A group project developed in completion of the Machine Learning module (Module Code: INT2) on the BEng Computer Science course at the University of York.

Overview

image-classification.py loads the Oxford Flowers 102 dataset via tensorflow_datasets, applies preprocessing/augmentation, builds a custom residual CNN from scratch, trains it, evaluates it on a test set, and saves the trained model.

Data Pipeline

  • Dataset: oxford_flowers102 (train / test / validation splits) loaded with tfds.load(as_supervised=True).
  • Preprocessing (applied to all splits):
    • Central crop (80% of the image)
    • Resize to 224x224
  • Augmentation (train split only):
    • Random left-right flip
    • Shuffle (buffer size 1024)
  • All splits are batched (batch size 32) and prefetched with tf.data.AUTOTUNE.

Model Architecture

A custom ResNet-style network (NeuralNetwork, subclassing tf.keras.Model):

  • Stem (start): Conv2D(64, 7x7, stride 2) -> ReLU -> MaxPooling2D(3x3, stride 2)
  • Residual body (resnetMiddle): a stack of residual blocks with increasing filter sizes (64 -> 128 -> 256 -> 512), built from two custom layer types:
    • NetworkBlockOne: downsampling block (first conv uses stride 2); adds a skip connection when input/output shapes match.
    • NetworkBlockTwo: same-resolution block (both convs use stride 1, padding='same'); adds a skip connection when input/output shapes match.
    • Each stage pairs one NetworkBlockOne (except the first stage, which uses two NetworkBlockTwo) with one NetworkBlockTwo.
  • Head (end): GlobalAveragePooling2D -> Dropout(0.8) -> Dense(102, activation='softmax') for the 102 flower classes.

Training

  • Optimizer: Adamax (learning_rate=0.005)
  • Loss: sparse categorical crossentropy
  • Metric: accuracy
  • Epochs: up to 300, with a custom early-stopping callback (MyCallBack) that halts training once validation accuracy reaches 57.5%
  • Validation is run every epoch against the validation split.

After training, the model is evaluated on the held-out test set and saved to disk under the name "Image Classifier".

Requirements

Usage

python image-classification.py

This will download the Oxford Flowers 102 dataset (on first run), train the model, print test evaluation metrics, and save the trained model to a directory named Image Classifier.

Notes / Possible Improvements

  • ReduceLROnPlateau is imported but not currently used in training.
  • The Adamax optimizer instance built with custom parameters is unused - model.compile refers to the optimizer by string name ('Adamax') instead, so it trains with default Adamax hyperparameters rather than learning_rate=0.005.

About

A TensorFlow/Keras image classifier that trains a custom ResNet-style convolutional neural network to classify flower images from the Oxford Flowers 102 dataset (102 flower categories)

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages