Your browser is not supported. Please update it.

26 October 2021

TensorFlow Lite gets even lighter to support ML analytics on IoT devices

Norway’s Nordic Semiconductor has added embedded machine learning (ML) software to its cellular-based IoT chipset portfolio, aiming to capitalize on the fast-gathering groundswell around IoT edge analytics and other functionality where remote execution in the cloud is unfeasible or undesirable for various reasons.

This has come about through Nordic Semi’s partnership with US-based Edge Impulse, which makes miniaturized ML tools for chips in resource-constrained IoT modules, under the banner of ‘TinyML’.

The pair had prepared the ground by launching TinyML support for the Norwegian firm’s nRF52 and nRF53 series of Bluetooth Low Energy (BLE) chips at the start of 2021. It is now offering the same with its nRF9160 development kit and Thingy:91 prototyping platform, which both combine the firm’s cellular-based low power WAN nRF9160 system-in-package (SiP) – featuring dual-mode NB-IoT and LTE-M – plus GPS, on the same developer board as its low power short range nRF52 BLE unit. IoT designers can now add TinyML to their nRF9160 SiP prototypes.

TinyML is the name that has been adopted for a stripped-down version of ML designed to execute in IoT edge devices such as wireless sensors at very low power levels measured in mW or even lower. It has been standardized and promoted by the TinyML Foundation, founded by a few individuals within Google and Qualcomm, which now sponsor regular online meetings and an annual brainstorming conference. That has galvanized rapid development in the IoT ML field over the last two years, indeed over the course of the Covid-19 pandemic.

The first point to note is that ML applies techniques in the realm of statistical regression and conditional probability in convergence or training of models for making accurate predictions from subsequent data in the field, or to detect significant patterns contained within those. This involves training from existing data sets and then execution of inference on input data. The training process is generally more computationally intensive but not time critical, so is best performed on large processors in a data center in the cloud.

It is the inference that for IoT must be as computationally efficient as possible, and with that end in mind the TensorFlow open source software library widely used for developing ML software whose elements are incorporated in inference engines had to be stripped down to barer essentials.

Originally developed by Google for internal use, TensorFlow is a software architecture including tools for developing and implementing ML algorithms for a variety of hardware platforms, including CPUs, GPUs and TPUs (tensor processing units) designed specifically for ML, targeting desktops, servers and indeed edge devices. The name tensor applies to the multidimensional arrays of numbers that often feed ML models. For example, the diagnostic measurements of temperature, blood pressure and cholesterol level associated with each patient would populate a 3D model in healthcare.

TensorFlow Lite was developed specifically for edge platforms, reducing need for access to resources in a data center. However, this was designed for rather more capable edge devices than remote sensors, still requiring a light on-premise server capable of providing a gateway to the Internet. But the far IoT edge includes devices that may have intermittent connectivity to the Internet, or none at all directly, being controlled solely by intermediate gateways that themselves might be capable of running TensorFlow Lite.

As a result, under the auspices of TinyML, another round of stripping-down has been carried out, leading to TensorFlow Lite for Microcontrollers. In fact, this represents a more profound reduction, since while it can still interpret code for direct execution, it can no longer rely on a whole file system and dynamic memory allocation. It must be able to run trained ML models as arrays that can be stored in read-only parts of the device, without any OS to rely on for memory allocation, which must be done manually.

The ML software also has no access to any external portions of the program. Execution must take place without being able to read an external file, with any software in libraries dynamically linked when the algorithms were compiled to avoid the need to have them available in these small devices at run time. The result is a small software interpreter for running ML inferences that fits into less than 16KB of memory on an ARM Cortex M3 system.

There are also limitations when it comes to execution of the algorithms, which again reduces need for processing resources and cuts energy consumption, which is becoming increasingly important for devices that may rely on batteries or say local solar or wind electricity generation. Indeed, TensorFlow Lite for Microcontrollers supports only a subset of TensorFlow operations and is ported to individual target devices, so that at run time there will limited processing capability available.

It is still not clear how small TinyML will be able to go, which depends partly on the application or use case, since the idea is to implement just those functions that are required, while the fuller TensorFlow Lite still retained a broad set of more diverse capabilities.

That is where the latest Nordic Semiconductor chips come in with its nRF9160 and Thingy:91 development units, designed for prototyping cellular IoT products that have been integrated into its Edge Impulse Studio platform, which can collect data from sensors, train ML models, and then deploy then onto target devices. The availability on Edge Impulse allows developers without TinyML expertise to start applying inferencing at device level.

These devices incorporate an ARM Cortex-M33 application processor, which provides the power to drive the TinyML functions, also with 1MB Flash and 256KB of RAM, so a tiny fraction of the dynamic memory available on say a smartphone. We should note the distinction here between the ARM Cortex-M3 and Cortex-M33. The Cortex-M3 processor that was the target for TinyML was developed for a broad range of devices including microcontrollers, automotive body systems, industrial control systems and wireless networking and sensors. The Cortex-M33 was then dedicated more specifically to IoT and embedded applications that require highly efficient security and digital signal control.

Cortex-M33 has various optional features that include TrustZone security for hardware-enforced isolation of critical code or data, as well as coprocessor interface, memory protection units, and a floating-point unit. These are not needed for some devices, for example where security is not critical, so there is scope for optimizing energy efficiency by avoiding those.

As Joakim Tønnesen, technical product manager at Nordic Semiconductor, summed up: “The introduction of TinyML for nRF9160 SiP-based low power cellular IoT applications allows developers to quickly move beyond experimenting with ML code and building up expertise. Instead, developers can focus on the best way to use their hard-won data as the foundation of innovative and exciting cellular IoT applications.”