Posted by Kateryna Semenova – Senior Developer Relations Engineer and Mark Sherwood – Senior Product Supervisor
Throughout AI on Android Highlight Week, we’re diving into how one can deliver your personal AI mannequin to Android-powered gadgets reminiscent of telephones, tablets, and past. By leveraging the instruments and applied sciences obtainable from Google and different sources, you may run refined AI fashions instantly on these gadgets, opening up thrilling potentialities for higher efficiency, privateness, and usefulness.
Understanding on-device AI
On-device AI entails deploying and executing machine studying or generative AI fashions instantly on {hardware} gadgets, as an alternative of counting on cloud-based servers. This strategy provides a number of benefits, reminiscent of decreased latency, enhanced privateness, price saving and fewer dependence on web connectivity.
For generative textual content use circumstances, discover Gemini Nano that’s now obtainable in experimental entry by its SDK. For a lot of on-device AI use circumstances, you would possibly need to bundle your personal fashions in your app. In the present day we’ll stroll by how to take action on Android.
Key assets for on-device AI
The Google AI Edge platform offers a complete ecosystem for constructing and deploying AI fashions on edge gadgets. It helps numerous frameworks and instruments, enabling builders to combine AI capabilities seamlessly into their functions. The Google AI Edge platforms consists of:
- MediaPipe Duties – Cross-platform low-code APIs to sort out widespread generative AI, imaginative and prescient, textual content, and audio duties
- LiteRT (previously often called TensorFlow Lite) – Light-weight runtime for deploying customized machine studying fashions on Android
- MediaPipe Framework – Pipeline framework for chaining a number of ML fashions together with pre and submit processing logic

The best way to construct customized AI options on Android
1. Outline your use case: Earlier than diving into technical particulars, it is essential to obviously outline what you need your AI function to realize. Whether or not you are aiming for picture classification, pure language processing, or one other software, having a well-defined objective will information your growth course of.
2. Select the best instruments and frameworks: Relying in your use case, you would possibly be capable to use an out of the field resolution otherwise you would possibly must create or supply your personal mannequin. Look by MediaPipe Duties for widespread options reminiscent of gesture recognition, picture segmentation or face landmark detection. In the event you discover a resolution that aligns together with your wants, you may proceed on to the testing and deployment step.

If that you must create or supply a customized mannequin to your use case, you’ll need an on-device ML framework reminiscent of LiteRT (previously TensorFlow Lite). LiteRT is designed particularly for cell and edge gadgets and offers a light-weight runtime for deploying machine studying fashions. Merely comply with these substeps:
a. Develop and practice your mannequin: Develop your AI mannequin utilizing your chosen framework. Coaching may be carried out on a robust machine or cloud surroundings, however the mannequin ought to be optimized for deployment on a tool. Strategies like quantization and pruning can assist cut back the mannequin dimension and enhance inference velocity. Mannequin Explorer can assist perceive and discover your mannequin as you are working with it.
b. Convert and optimize the mannequin: As soon as your mannequin is skilled, convert it to a format appropriate for on-device deployment. LiteRT, for instance, requires conversion to its particular format. Optimization instruments can assist cut back the mannequin’s footprint and improve efficiency. AI Edge Torch lets you convert PyTorch fashions to run regionally on Android and different platforms, utilizing Google AI Edge LiteRT and MediaPipe Duties libraries.
c. Speed up your mannequin: You may velocity up mannequin inference on Android through the use of GPU and NPU. LiteRT’s GPU delegate lets you run your mannequin on GPU immediately. We’re working laborious on constructing the following technology of GPU and NPU delegates that may make your fashions run even sooner, and allow extra fashions to run on GPU and NPU. We’d prefer to invite you to take part in our early entry program to check out this new GPU and NPU infrastructure. We’ll choose members out on a rolling foundation so don’t wait to succeed in out.
3. Take a look at and deploy: To make sure that your mannequin delivers the anticipated efficiency throughout numerous gadgets, rigorous testing is essential. Deploy your app to customers after finishing the testing section, providing them a seamless and environment friendly AI expertise. We’re engaged on bringing the advantages of Google Play and Android App Bundles to delivering customized ML fashions for on-device AI options. Play for On-device AI takes the complexity out of launching, concentrating on, versioning, downloading, and updating on-device fashions with the intention to provide your customers a greater consumer expertise with out compromising your app’s dimension and at no extra price. Full this type to precise curiosity in becoming a member of the Play for On-device AI early entry program.
Construct belief in AI by privateness and transparency
With the rising function of AI in on a regular basis life, making certain fashions run as meant on gadgets is essential. We’re emphasizing a “zero belief” strategy, offering builders with instruments to confirm system integrity and consumer management over their knowledge. Within the zero belief strategy, builders want the flexibility to make knowledgeable selections concerning the system’s trustworthiness.
The Play Integrity API is really useful for builders seeking to confirm their app, server requests, and the system surroundings (and, quickly, the recency of safety updates on the system). You may name the API at vital moments earlier than your app’s backend decides to obtain and run your fashions. You can even take into account turning on integrity checks for putting in your app to cut back your app’s distribution to unknown and untrusted environments.
Play Integrity API makes use of Android Platform Key Attestation to confirm {hardware} parts and generate integrity verdicts throughout the fleet, eliminating the necessity for many builders to instantly combine completely different attestation instruments and lowering system ecosystem complexity. Builders can use one or each of those instruments to evaluate system safety and software program integrity earlier than deciding whether or not to belief a tool to run AI fashions.
Conclusion
Bringing your personal AI mannequin to a tool entails a number of steps, from defining your use case to deploying and testing the mannequin. With assets like Google AI Edge, builders have entry to highly effective instruments and insights to make this course of smoother and more practical. As on-device AI continues to evolve, leveraging these assets will allow you to create cutting-edge functions that supply enhanced efficiency, privateness, and consumer expertise. We’re presently in search of early entry companions to check out a few of our newest instruments and APIs at Google AI Edge. Merely fill on this kind to attach and discover how we are able to work collectively to make your imaginative and prescient a actuality.
Dive into these assets and begin exploring the potential of on-device AI—your subsequent massive innovation may very well be only a mannequin away!
Use #AndroidAI hashtag to share your suggestions or what you have constructed on social media and meet up with the remainder of the updates being shared throughout Highlight Week: AI on Android.