Machine Learning (ML) models are becoming increasingly popular to help enhance decision-making. As we live in a mobile-first world, it becomes very important to make inferences from these ML models on mobile devices, but this comes with a challenge, which is to be able to use these models on phones and tablets due to performance and other constraints. As a firm that focuses on building mobile apps, we at Unvired are being asked to help integrate ML models on mobile platforms in an offline environment. So, we researched and identified how to achieve this integration. The integration needs to be performed for each platform one at a time—iOS, Android, Windows, and the Web (browser).
However, integration with mobile or web apps intending to use these ML models on mobile devices is only half the battle. There is the whole other topic of how one keeps the model trained/updated regularly as more input is fed into the model and the updated model downloaded to make the most optimal inferences. And, to monitor the model performance and drift and course correct it. Or, even evaluate multiple models to evaluate the best fit. This is the realm of MLOps, and we will dig into it in a later blog. In fact, this introductory blog shall be followed by a series of blogs during which we will dive deeper into how one can deploy ML models for various mobile OS/Web as well as explore how MLOps can be used to manage the lifecycle of model deployment and continuous improvement.
Let us provide you with a trailer of the upcoming blogs with some high-level thoughts on integrating ML models on iPhones (Apple/iOS devices). The following are the steps to create this integration:
1. Select/Train an ML model: This model can be based on TensorFlow or PyTorch. We suggest using a TensorFlow model. Note that to use on mobile devices, you will have to use TensorFlow Lite, which are ML model optimized to run on mobile devices. In order to get a Tensor Flow Lite model, you can use a pre-built official TensorFlow Lite models or convert a TensorFlow model to TensorFlow Lite.
2. Deploy the ML model: Deploy your custom TensorFlow models using either the Firebase console or the Firebase Admin Python and Node.js SDKs. Add a custom model to your Firebase project.
3. Download the ML model: To use your TensorFlow Lite model in your app, first use the Firebase ML SDK to download the latest version of the model to the device.
4. Perform Inference on Input Data: The TensorFlow Lite model interpreter takes as input and produces as output one or more multidimensional arrays. Before you can pass data to a model or use its result, you must know the number and dimensions (“shape”) of the arrays your model uses. In other words, you need to determine your model’s Input and Output shapes.
After you have determined the format of your model’s input and output, get your input data and perform any transformations on the data that are necessary to get an input of the right shape for your model.
The link below provides more details on how to implement this integration:
Use a custom TensorFlow Lite model on Apple platforms | Firebase ML (google.com)
This blog has set the stage for the ML Blog series in which we will share with you detailed insights that we have gleaned from some Proof of Concepts we have conducted. Stay tuned for more.