Practical guideMethodology & analyticsComputer science

TinyML for researchers: a practical study guide

TinyML runs machine learning inference on microcontrollers with kilobytes of memory and milliwatt power budgets. This guide explains the workflow, quantisation, benchmarks and reporting standards that a doctoral TinyML study needs.

What you will learn

  • Explain what TinyML is and which resource limits shape it
  • Describe the workflow from data collection to on-device deployment
  • Explain how 8-bit integer quantisation works and what it costs
  • Use the MLPerf Tiny tasks as baselines for a study
  • Choose what to report so that a TinyML result can be judged and replicated

What you will unlearn

  • TinyML is a software framework.TinyML is a field; TensorFlow Lite Micro and other runtimes are frameworks used within it.
  • Quantisation converts 64-bit models to 8-bit.Models are usually trained in 32-bit floating point and quantised to 8-bit integers, with biases kept at 32 bits.
  • The whole machine learning pipeline runs on the microcontroller.Training normally happens off-device; the microcontroller runs inference.
  • A high accuracy figure is enough to show a TinyML model works.Latency, energy and memory must be reported alongside accuracy, measured on the device.

Skills you will practise

  • Embedded machine learning
  • Model quantisation
  • Benchmarking
  • On-device measurement
  • Experimental reporting

What TinyML is

Tiny machine learning (TinyML) is the practice of running machine learning inference on microcontrollers and other ultra-low-power devices, so that sensors can interpret data where it is collected instead of sending everything to the cloud. It is a field of research and engineering rather than a single framework: several software frameworks, model design methods and hardware platforms contribute to it (Banbury et al., 2021a; Banbury et al., 2021c).

The appeal is practical. A device that recognises a spoken keyword, detects a person in view or flags an unusual machine sound locally can respond quickly, work without a network connection, keep raw data on the device and run for long periods on a small battery. The difficulty is equally practical: the devices are far smaller than the phones and servers on which most machine learning is developed.

Banbury et al. (2021a) summarise the scale of the constraint. TinyML systems typically have a few hundred kilobytes of memory and processors clocked in megahertz, resources about two orders of magnitude smaller than a smartphone, and power budgets up to four orders of magnitude smaller than conventional systems, often below a milliwatt. Almost every methodological choice in TinyML research follows from these limits.

An important clarification for new researchers: in most current TinyML work, models are trained on an ordinary computer or in the cloud and only inference runs on the microcontroller. On-device training is an active but much less mature research area.

Machine learning foundations you need

A common definition says a program learns when its performance at a task improves with experience. In TinyML terms, the task might be classifying one-second audio clips, the experience is a labelled or unlabelled dataset, and performance is a measure of how well the task is done, such as accuracy or the area under the ROC curve. Resource cost (memory, latency and energy) is a separate set of measures that TinyML adds on top, and good studies report both (Banbury et al., 2021c).

Table 1. Supervised and unsupervised learning in TinyML.
Supervised learningUnsupervised learning
DataLabelled examples of inputs and the correct outputsUnlabelled data; the model finds structure itself
Typical TinyML taskKeyword spotting, person detection, image classificationAnomaly detection in machine sounds or vibration
Example benchmark dataSpeech Commands (Warden, 2018); Visual Wake Words (Chowdhery et al., 2019)ToyADMOS machine-operating sounds (Koizumi et al., 2019)
Main riskLabels that are noisy or unrepresentative of the deployment settingNormal behaviour in training that differs from normal behaviour in the field

Anomaly detection shows why unsupervised methods matter on small devices. Faults are rare, so it is often easier to train a compact autoencoder on normal operating data and treat inputs it reconstructs poorly as possible anomalies; the MLPerf Tiny anomaly detection task uses a small fully connected autoencoder in this role (Banbury et al., 2021c).

From data to device: the TinyML workflow

  1. 1Collect and label sensor data
  2. 2Train a compact model
  3. 3Validate and tune
  4. 4Quantise and convert
  5. 5Deploy as firmware
  6. 6Measure accuracy, latency, energy and memory
Figure 1. A typical TinyML workflow. Training happens off-device; the microcontroller runs inference.

1. Data collection

Collect data with the same sensor, sampling rate and placement that the deployed device will use. A model trained on studio-quality audio may fail on a cheap microphone in a noisy room. Record how data were labelled and cleaned, and keep a held-out test set that reflects deployment conditions.

2. Model training

Models are usually trained in standard frameworks such as TensorFlow, Keras or PyTorch. Architectures are chosen with the target memory in mind: depthwise separable convolutions, as in MobileNets (Howard et al., 2017) and the DS-CNN keyword spotting models of Zhang et al. (2017), reduce computation and parameter counts substantially compared with standard convolutions.

3. Optimisation and model search

Hyperparameter tuning trades accuracy against size and latency. Neural architecture search can be constrained directly by microcontroller memory, as in SpArSe (Fedorov et al., 2019) and MicroNets (Banbury et al., 2021b), which search for networks that fit the flash and RAM of commodity microcontrollers.

4. Quantisation and conversion

Most models are trained with 32-bit floating-point numbers. Integer quantisation maps weights and activations to 8-bit integers, with biases held as 32-bit integers, using an affine mapping between real values and integers defined by a scale and a zero-point (Jacob et al., 2018). Because each weight then needs one byte instead of four, weight storage falls by roughly a factor of four, and integer arithmetic suits microcontrollers that lack fast floating-point units. Quantisation can be applied after training or simulated during training (quantisation-aware training), which usually limits the accuracy loss; Jacob et al. (2018) reported, for example, ResNet-50 ImageNet accuracy of 74.9% after 8-bit quantisation against 76.4% in floating point. Eight-bit integers were the most common numerical format among MLPerf Tiny submissions (Banbury et al., 2021c).

The quantised model is then converted to a format the device runtime can read. TensorFlow Lite Micro, for instance, runs converted TensorFlow Lite models through a small interpreter designed for devices without an operating system (David et al., 2020). Code generation and hand-written kernels are the main alternatives, and the choice affects portability and reproducibility (Banbury et al., 2021a).

5. Deployment and monitoring

The model is compiled into firmware with the code that reads the sensor and acts on predictions. Measure accuracy on the device as well as in simulation: quantisation, input pre-processing and real sensor noise can all change results.

Benchmarks: how TinyML systems are compared

Comparing TinyML systems is hard because hardware, software stacks and measurement methods vary widely (Banbury et al., 2021a). MLPerf Tiny, developed by more than 50 organisations from industry and academia, is the first industry-standard benchmark suite for these systems. It measures accuracy, latency and energy on four tasks with fixed reference models and quality targets (Banbury et al., 2021c).

Table 2. The four MLPerf Tiny benchmark tasks, as reported by Banbury et al. (2021c).
TaskDatasetReference model (size)Quality target
Keyword spottingSpeech Commands (Warden, 2018)DS-CNN (52.5 KB)90% top-1 accuracy
Visual wake wordsVisual Wake Words (Chowdhery et al., 2019)MobileNetV1 (325 KB)80% top-1 accuracy
Image classificationCIFAR-10 (Krizhevsky et al., 2009)ResNet (96 KB)85% top-1 accuracy
Anomaly detectionToyADMOS (Koizumi et al., 2019)Fully connected autoencoder (270 KB)0.85 AUC

For doctoral work, the benchmark is useful in two ways. It gives you recognised baselines to compare against, and it models good reporting practice: a stated quality target, a fixed dataset, a reference model and a defined measurement method. The image classification model is a small residual network in the tradition of He et al. (2016), scaled down to fit microcontroller memory.

Applications and research directions

Table 3. Application areas and the research questions they raise.
Application areaExample taskResearch questions it raises
Smart sensors in buildingsDetecting whether a person is present from a low-resolution cameraHow small can a person detector be before accuracy falls below a useful level?
Wearables and health monitoringRecognising a spoken keyword or a movement patternHow well do models trained on public data transfer to new users and devices?
Industrial monitoringFlagging unusual machine sounds or vibrationHow should anomaly thresholds adapt as machines age?
Agriculture and environmentClassifying sounds or images in the field on battery powerHow do energy budgets limit sampling rate and model size over a season?

Several open problems run across these areas. Energy measurement at sub-milliwatt levels is itself difficult, and fair comparison across heterogeneous hardware and software stacks remains unsettled (Banbury et al., 2021a). Designing models jointly with the memory limits of specific devices is an active line of work (Fedorov et al., 2019; Banbury et al., 2021b). On-device learning, privacy and robustness to changing field conditions are less mature. For a fuller treatment of open gaps and recent literature, see our TinyML future research directions brief.

When choosing a doctoral topic, start from the application constraint rather than the technique. A question such as "Can a keyword spotter run for a year on a coin cell while staying above a stated accuracy?" defines the task, the quality threshold and the resource budget at once, and it tells you which measurements will settle the answer. A question such as "Can deep learning be used on microcontrollers?" has already been answered by the benchmark literature (Banbury et al., 2021c). Contributions at doctoral level typically come from one of three places: a new model or compression method that improves the accuracy and resource trade-off on recognised tasks, a careful study of a real deployment setting that the public benchmarks do not represent, or better methods for measuring and comparing systems. Each needs a clear baseline, and each needs results measured on real hardware rather than estimated from model size alone.

Worked example: framing a doctoral TinyML study

The following example is illustrative. A doctoral researcher wants to detect bearing faults in small pumps using a vibration sensor and a low-cost microcontroller, without a network connection.

  1. Question. How accurately can an 8-bit quantised autoencoder running on a microcontroller detect early bearing faults, and at what energy cost per inference?
  2. Baseline. Use the MLPerf Tiny anomaly detection reference model as a starting architecture and compare it with a smaller variant found by constrained search (Banbury et al., 2021c; Banbury et al., 2021b).
  3. Data. Record normal operation on several pumps and a smaller set of seeded faults for testing only.
  4. Measurement. Report AUC on device, latency, energy per inference, flash and RAM use, and the measurement set-up, following the benchmark's practice.
  5. Threats to validity. Test on pumps not seen in training, and report how results change after quantisation.
Table 4. What a TinyML study should report.
What to reportWhy it matters
Hardware: microcontroller, clock speed, flash and RAMResults do not transfer across devices without it
Software stack: framework, runtime and versionInterpreters, code generators and hand-written kernels differ
Numerical format: float32, int8 or other; post-training or quantisation-awareExplains accuracy changes
Task quality: accuracy, AUC or F1 on a held-out set measured on the deviceShows the model still works
Latency and energy per inference, with the measurement methodEnergy is the core TinyML constraint
Data: source, sensor, sampling rate, split and labellingAllows replication and judging transferability

Common mistakes

  • Reporting accuracy only. Without latency, energy and memory, a TinyML result cannot be judged (Banbury et al., 2021c).
  • Measuring only in simulation. On-device results can differ after quantisation and with real sensor input.
  • Misdescribing quantisation. The usual step is from 32-bit floating point to 8-bit integers, not from 64-bit; state which values are quantised and how (Jacob et al., 2018).
  • Ignoring the software stack. The same model can perform differently under different runtimes (Banbury et al., 2021a; David et al., 2020).
  • Training on unrepresentative data. Public datasets are a starting point; deployment data from your own sensors are needed to test transfer.

Key takeaways

  • TinyML works within memory and power budgets orders of magnitude smaller than phones or servers (Banbury et al., 2021a).
  • Integer quantisation from 32-bit floating point to 8-bit integers cuts weight storage about fourfold and suits microcontroller arithmetic (Jacob et al., 2018).
  • MLPerf Tiny offers four recognised tasks, datasets and reference models to benchmark against (Banbury et al., 2021c).
  • Report hardware, software stack, numerical format, on-device quality, latency and energy together (Banbury et al., 2021c; David et al., 2020).
  • Architecture search constrained by device memory is an active route to smaller, accurate models (Banbury et al., 2021b).
Your next step

Want to apply this to your own study?

  1. 1Tell us your topic, data and deadline
  2. 2A statistician reviews your work with you
  3. 3You get a plan and a quote

References

  1. Banbury, C. R., Janapa Reddi, V., Lam, M., Fu, W., Fazel, A., Holleman, J., Huang, X., Hurtado, R., Kanter, D., Lokhmotov, A., Patterson, D., Pau, D., Seo, J., Sieracki, J., Thakker, U., Verhelst, M., & Yadav, P. (2021a). Benchmarking TinyML systems: Challenges and direction (arXiv:2003.04821v4). arXiv. https://arxiv.org/abs/2003.04821
  2. Banbury, C., Janapa Reddi, V., Torelli, P., Jeffries, N., Kiraly, C., Holleman, J., Montino, P., Kanter, D., Warden, P., Pau, D., Thakker, U., Torrini, A., Cordaro, J., Di Guglielmo, G., Duarte, J., Tran, H., Tran, N., Wenxu, N., & Xuesong, X. (2021c). MLPerf Tiny benchmark. In Proceedings of the Neural Information Processing Systems Track on Datasets and Benchmarks (Vol. 1). https://datasets-benchmarks-proceedings.neurips.cc/paper/2021/hash/da4fb5c6e93e74d3df8527599fa62642-Abstract-round1.html
  3. Banbury, C., Zhou, C., Fedorov, I., Matas, R., Thakker, U., Gope, D., Janapa Reddi, V., Mattina, M., & Whatmough, P. (2021b). MicroNets: Neural network architectures for deploying TinyML applications on commodity microcontrollers. Proceedings of Machine Learning and Systems, 3.
  4. Chowdhery, A., Warden, P., Shlens, J., Howard, A., & Rhodes, R. (2019). Visual wake words dataset (arXiv:1906.05721). arXiv. https://arxiv.org/abs/1906.05721
  5. David, R., Duke, J., Jain, A., Janapa Reddi, V., Jeffries, N., Li, J., Kreeger, N., Nappier, I., Natraj, M., Regev, S., Rhodes, R., Wang, T., & Warden, P. (2020). TensorFlow Lite Micro: Embedded machine learning on TinyML systems (arXiv:2010.08678). arXiv. https://arxiv.org/abs/2010.08678
  6. Fedorov, I., Adams, R. P., Mattina, M., & Whatmough, P. (2019). SpArSe: Sparse architecture search for CNNs on resource-constrained microcontrollers. In Advances in Neural Information Processing Systems, 32 (pp. 4978–4990). Curran Associates.
  7. He, K., Zhang, X., Ren, S., & Sun, J. (2016). Deep residual learning for image recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (pp. 770–778).
  8. Howard, A. G., Zhu, M., Chen, B., Kalenichenko, D., Wang, W., Weyand, T., Andreetto, M., & Adam, H. (2017). MobileNets: Efficient convolutional neural networks for mobile vision applications (arXiv:1704.04861). arXiv. https://arxiv.org/abs/1704.04861
  9. Jacob, B., Kligys, S., Chen, B., Zhu, M., Tang, M., Howard, A., Adam, H., & Kalenichenko, D. (2018). Quantization and training of neural networks for efficient integer-arithmetic-only inference. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (pp. 2704–2713). https://doi.org/10.1109/CVPR.2018.00286
  10. Koizumi, Y., Saito, S., Uematsu, H., Harada, N., & Imoto, K. (2019). ToyADMOS: A dataset of miniature-machine operating sounds for anomalous sound detection. In 2019 IEEE Workshop on Applications of Signal Processing to Audio and Acoustics (WASPAA) (pp. 313–317). IEEE.
  11. Krizhevsky, A., Nair, V., & Hinton, G. (2009). The CIFAR-10 dataset [Data set]. University of Toronto. https://www.cs.toronto.edu/~kriz/cifar.html
  12. Warden, P. (2018). Speech commands: A dataset for limited-vocabulary speech recognition (arXiv:1804.03209). arXiv. https://arxiv.org/abs/1804.03209
  13. Zhang, Y., Suda, N., Lai, L., & Chandra, V. (2017). Hello edge: Keyword spotting on microcontrollers (arXiv:1711.07128). arXiv. https://arxiv.org/abs/1711.07128

How to cite this article

Choose your referencing style, then copy. Check your university's or journal's guide for local variations.

PhD Research Lab Academy. (2024, September 30). TinyML for researchers: a practical study guide. PhD Research Lab. https://www.phdassistance.com/insights/study-guide-on-tinyml/

PhD Research Lab Academy. “TinyML for Researchers: A Practical Study Guide.” PhD Research Lab, 30 Sept. 2024, www.phdassistance.com/insights/study-guide-on-tinyml. Accessed [access date].

PhD Research Lab Academy (2024) TinyML for researchers: a practical study guide. PhD Research Lab. Available at: https://www.phdassistance.com/insights/study-guide-on-tinyml/ (Accessed: [access date]).

PhD Research Lab Academy. “TinyML for Researchers: A Practical Study Guide.” PhD Research Lab. September 30, 2024. https://www.phdassistance.com/insights/study-guide-on-tinyml.

PhD Research Lab Academy, ‘TinyML for Researchers: A Practical Study Guide’ (PhD Research Lab, 30 September 2024) <https://www.phdassistance.com/insights/study-guide-on-tinyml> accessed [access date].

PhD Research Lab Academy. TinyML for researchers: a practical study guide [Internet]. PhD Research Lab; 2024 Sep 30 [cited [access date]]. Available from: https://www.phdassistance.com/insights/study-guide-on-tinyml/

PhD Research Lab Academy, “TinyML for researchers: a practical study guide,” PhD Research Lab, Sept. 30, 2024. [Online]. Available: https://www.phdassistance.com/insights/study-guide-on-tinyml. [Accessed: [access date]].

@online{tinyml_study_guide_2024,
  author = {{PhD Research Lab Academy}},
  title = {{TinyML for researchers: a practical study guide}},
  organization = {PhD Research Lab},
  date = {2024-09-30},
  url = {https://www.phdassistance.com/insights/study-guide-on-tinyml},
  urldate = {[access date]}
}

This article is for learning. Use it to understand the method and cite the original sources above in your own work; do not copy or submit it as your own.

TinyML for researchersNeed help applying it to your study?