FloraSense – Plant Health Score (TFLite)
A tiny regression model that estimates a plant health score from four environmental sensor readings. It was built for FloraSense, an IoT plant-monitoring system developed as the undergraduate thesis (TCC) of Pedro Domitti de Carvalho in Computer Engineering at PUC-Campinas, and is designed to run on-device with TensorFlow Lite for Microcontrollers.
- Source code: github.com/pedrodcarvalho/flora-sense
- Model size: ~11.6 KB (
.tflite, float32) - Task: tabular regression (4 inputs → 1 score)
Files
| File | Description |
|---|---|
plant_health_model.tflite | TensorFlow Lite model (float32) |
plant_health_model.h | Same model as a C byte array, for TFLite Micro on microcontrollers (ESP32) |
plant_health_model.keras | Original Keras model |
scaler.pkl | Fitted scikit-learn StandardScaler (joblib/pickle) |
scaler.json | Scaler mean/scale as plain JSON (no pickle needed) |
Inputs and output
Input: float32[1, 4], standardized with the scaler below, in this order:
| # | Feature | Mean | Std |
|---|---|---|---|
| 0 | temperature (°C) | 25.058 | 2.936 |
| 1 | humidity (%) | 60.708 | 9.970 |
| 2 | light (lux) | 19859.787 | 3020.656 |
| 3 | soil_moisture (%) | 45.088 | 14.744 |
scaled = (raw - mean) / std
Output: float32[1, 1] – predicted plant health score (raw regression value, roughly 0–100).
Architecture and training
- Keras
Sequential:Dense(64, relu)→Dense(32, relu)→Dense(1)(linear) - Loss: MSE · Optimizer: Adam · 20 epochs · 80/20 train/validation split
- Dataset: 1,000 samples of sensor readings with a health score (
ml/datasets/plant_health.csvin the source repo) - Final validation MSE ≈ 258.6 (RMSE ≈ 16 score points)
- Converted with
tf.lite.TFLiteConverter.from_keras_model(no quantization)
Usage (Python)
import numpy as np
import tensorflow as tf
mean = np.array([25.05799617, 60.70836237, 19859.78719911, 45.08751322], dtype=np.float32)
std = np.array([2.93617862, 9.96955525, 3020.65628, 14.7444365], dtype=np.float32)
# [temperature, humidity, light, soil_moisture]
raw = np.array([[26.49, 73.99, 18728.72, 34.87]], dtype=np.float32)
x = (raw - mean) / std
interpreter = tf.lite.Interpreter(model_path="plant_health_model.tflite")
interpreter.allocate_tensors()
interpreter.set_tensor(interpreter.get_input_details()[0]["index"], x.astype(np.float32))
interpreter.invoke()
score = interpreter.get_tensor(interpreter.get_output_details()[0]["index"])[0][0]
print(f"Predicted health score: {score:.2f}")
Usage (ESP32 / TFLite Micro)
Include plant_health_model.h and load plant_health_model_tflite with tflite::GetModel(...). Apply the same standardization on-device before filling the input tensor. See iot/src/main.cpp in the source repo for the full firmware.
Limitations
- Small dataset and a simple MLP; treat the score as an indicator, not a diagnosis.
- Not species-specific: the scaler and score reflect the training data's ranges. Readings far outside them will extrapolate poorly.
- Soil pH and nutrient level exist in the dataset but are not model inputs.
Citation
Carvalho, P. D. de. FloraSense: IoT plant monitoring with on-device machine learning.
Undergraduate thesis (Computer Engineering), PUC-Campinas, 2026.