Flower classifier (MobileNetV2, ONNX)

Image classifier that recognises 5 kinds of flowers. It is a transfer-learning model: a frozen ImageNet-pretrained MobileNetV2 backbone with a small dense head on top, trained in Keras and exported to ONNX (flower_model.onnx).

The model was built as part of the MLOps exercise (KdG, DAI 6). Training code, config and serving code live in the project repository under src/flower/.

Classes

The output is a probability vector of length 5, in this order:

index class
0 daisy
1 dandelion
2 roses
3 sunflowers
4 tulips

Model details

Architecture MobileNetV2(include_top=False, pooling="avg", weights="imagenet") (frozen) β†’ Dense(512, relu) β†’ Dense(5, softmax)
Input float32 tensor of shape (batch, 180, 180, 3)
Output float32 tensor of shape (batch, 5), softmax probabilities
Format ONNX (exported with keras.Model.export(..., format="onnx"))
Framework TensorFlow / Keras, tracked with MLflow, configured with Hydra

Preprocessing

The model expects images exactly as they were fed during training:

  • resized to 180 Γ— 180 (height Γ— width),
  • raw pixel values in the range 0–255 (no preprocess_input, no scaling to [0, 1]),
  • 3 colour channels.

Note: during training the images were loaded with image_dataset_from_directory (RGB), while the inference code in the repo (flower_model.py, flower_web.py) reads images with OpenCV (cv2.imread, BGR) without converting the channel order. For best results convert to RGB before inference.

How to use

import cv2
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download

CLASSES = ["daisy", "dandelion", "roses", "sunflowers", "tulips"]

model_path = hf_hub_download(repo_id="<user>/<repo>", filename="flower_model.onnx")
session = ort.InferenceSession(model_path)
input_name = session.get_inputs()[0].name

image = cv2.imread("my_flower.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (180, 180)).astype(np.float32)
batch = np.expand_dims(image, axis=0)

probabilities = session.run(None, {input_name: batch})[0][0]
print(CLASSES[int(np.argmax(probabilities))], float(probabilities.max()))

Training data

TensorFlow flower_photos (~3,670 photos, 5 classes, CC-BY licensed images from Flickr).

The dataset was expanded offline: every original image was resized to 200 Γ— 200 and stored as a center crop (180 Γ— 180) plus 5 augmented copies (random rotation with factor 0.2, i.e. up to Β±72Β°, random 180 Γ— 180 crop). The expanded set was split 80 / 20 into training and validation (seed=123).

Training procedure

Hyperparameter Value
Optimizer Adam
Learning rate 0.0005
Loss sparse categorical cross-entropy
Epochs 10
Batch size 32
Dense units 512
Backbone trainable no (frozen)

All hyperparameters are set in src/flower/config.yaml; every run is logged to MLflow (experiment flowers-classification), including the resolved config, per-epoch metrics, the Keras model, the ONNX export and class_names.json.

Evaluation

Results of the last training run (epoch 10):

Metric Train Validation
Accuracy 0.872 0.745
Loss 0.372 0.705

Limitations and bias

  • Validation leakage: the train/validation split is made after augmentation, so augmented copies of the same original photo can end up in both sets. The validation accuracy is therefore optimistic; there is no separate held-out test set.
  • Only 5 flower classes. Any other image (other flowers, non-flowers) will still be forced into one of these 5 classes.
  • The training photos are mostly close-ups from Flickr; performance on other kinds of images (drawings, far-away shots, unusual lighting) is unknown.
  • Intended for educational use only.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for gdepaepe/dai6

Quantized
(6)
this model

Evaluation results

  • Validation accuracy on TensorFlow flower_photos (augmented)
    self-reported
    0.745