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.
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.
- Dataset:
oxford_flowers102(train / test / validation splits) loaded withtfds.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.
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 twoNetworkBlockTwo) with oneNetworkBlockTwo.
- Head (
end):GlobalAveragePooling2D->Dropout(0.8)->Dense(102, activation='softmax')for the 102 flower classes.
- 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".
- Python 3
- tensorflow — core deep learning framework (Keras API, layers, models, optimizers, callbacks)
- tensorflow-datasets — provides
tfds.loadand theoxford_flowers102dataset
python image-classification.pyThis 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.
ReduceLROnPlateauis imported but not currently used in training.- The Adamax optimizer instance built with custom parameters is unused -
model.compilerefers to the optimizer by string name ('Adamax') instead, so it trains with default Adamax hyperparameters rather thanlearning_rate=0.005.