What’s new with Microsoft in open-source and Kubernetes at KubeCon North America 2024
At Microsoft, we are committed to innovation in the cloud-native ecosystem through…
ONNX Runtime now supports building mobile applications in C# with Xamarin. Support for Android and iOS is included in the ONNX Runtime release 1.10 NuGet package. This enables C# developers to build AI applications for Android and iOS to execute ONNX models on mobile devices with ONNX Runtime.
ONNX Runtime is the open source project that is designed to accelerate machine learning across a wide range of frameworks, operating systems, and hardware platforms. We had previously introduced ONNX Runtime Mobile as the product targeting smartphones and other small storage devices.
In today’s release 1.10 we are enabling support for developers to build cross-platform applications targeting Android and iOS using Xamarin.Forms. This package supports the execution of ONNX models on the device’s CPU using the default CPU Execution Provider. Some phone hardware contains specialized hardware (NPUs) for efficient ML execution via the NNAPI (Android) and CoreML (iOS) interfaces. With the ONNX Runtime Mobile package, developers can choose to use the NNAPI (Android) or CoreML (iOS) Execution Providers that are available in the package. Developers should test to compare the performance between the provider options to determine the optimal solution for the application and model execution. See NNAPI Options and Core ML Options for more details to optimize and tune performance and accuracy when using the platform-specific accelerators.
Xamarin is an open source app platform for building modern and performant iOS and Android apps with C# and .NET. With support for Android and iOS in the NuGet feed, developers can infuse AI in their applications with ONNX Runtime.
We have added a new sample for building a mobile application in Xamarin. This example runs an image classifier using ResNet to classify among well-known images. It is part of the onnxruntime-inference-examples repo. This sample uses the official ONNX Runtime NuGet package.
Add the ONNX Runtime package in your project:
PM> Install-Package Microsoft.ML.OnnxRuntime -Version 1.10.0
Include ONNX Runtime package in your code:
using Microsoft.ML.OnnxRuntime;
To use the NNAPI Execution Provider in Android set:
options.AppendExecutionProvider_Nnapi();
To use the CoreML Execution Provider in iOS set:
options.AppendExecutionProvider_CoreML(CoreMLFlags.COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE)
Getting started: This Xamarin blog post demonstrates the basic steps for building Xamarin.Forms applications integrating with ONNX Runtime to build AI solutions.
Version 1.10 is the latest release of the high-performance and cross-platform inference engine. Other notable updates include:
ONNX Runtime Mobile is a build of the ONNX Runtime inference engine targeting Android and iOS devices. With this package, developers can build smartphone applications optimized for smaller disk footprint. Smaller application packages are also useful to comply with size requirements for Android and iOS App Stores. There are two flavors of the ONNX Runtime Mobile package—the prebuilt package containing a subset of ONNX operator set focused on the mobile AI scenarios or a custom package that can be generated based on the specific models used by the AI application. Refer to these steps to generate the custom packages for Android and iOS. The prebuilt packages are available for various platforms and language bindings. Refer to the matrix of options for the package corresponding to specific platform-language bindings.