Commit a144865d authored by gaoqiong's avatar gaoqiong
Browse files

update v1.14.0

parent cf1acfd2
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Microsoft.ML.OnnxRuntime.InferenceSample.Forms.App">
<Application.Resources>
</Application.Resources>
</Application>
\ No newline at end of file
using Xamarin.Forms;
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Forms
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
protected override void OnStart() {}
protected override void OnSleep() {}
protected override void OnResume() {}
}
}
\ No newline at end of file
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Microsoft.ML.OnnxRuntime.InferenceSample.Forms.MainPage">
<StackLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label Text="Inference Sample" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
<Label Text="ONNX Runtime" FontSize="Title" Padding="30,10,30,10"/>
<Button x:Name="Start" Text="Run tests" Clicked="Start_Clicked" FontSize="Large" />
<Label x:Name="OutputLabel" Text="Output" FontSize="Small"/>
</StackLayout>
</ContentPage>
using System;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Forms
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
// in general create the inference session (which loads and optimizes the model) once and not per inference
// as it can be expensive and time consuming.
inferenceSampleApi = new InferenceSampleApi();
}
protected override void OnAppearing()
{
base.OnAppearing();
OutputLabel.Text = "Press 'Run Tests'.\n";
}
private readonly InferenceSampleApi inferenceSampleApi;
private async Task ExecuteTests()
{
Action<Label, string> addOutput = (label, text) =>
{
Device.BeginInvokeOnMainThread(() => { label.Text += text; });
Console.Write(text);
};
OutputLabel.Text = "Testing execution\nComplete output is written to Console in this trivial example.\n\n";
// run the testing in a background thread so updates to the UI aren't blocked
await Task.Run(() =>
{
addOutput(OutputLabel, "Testing using default platform-specific session options... ");
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n");
Thread.Sleep(1000); // artificial delay so the UI updates gradually
// demonstrate a range of usages by recreating the inference session with different session options.
addOutput(OutputLabel, "Testing using default platform-specific session options... ");
inferenceSampleApi.CreateInferenceSession(SessionOptionsContainer.Create());
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n");
Thread.Sleep(1000);
addOutput(OutputLabel, "Testing using named platform-specific session options... ");
inferenceSampleApi.CreateInferenceSession(SessionOptionsContainer.Create("ort_with_npu"));
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n");
Thread.Sleep(1000);
addOutput(OutputLabel, "Testing using default platform-specific session options via ApplyConfiguration extension... ");
inferenceSampleApi.CreateInferenceSession(new SessionOptions().ApplyConfiguration());
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n");
Thread.Sleep(1000);
addOutput(OutputLabel, "Testing using named platform-specific session options via ApplyConfiguration extension... ");
inferenceSampleApi.CreateInferenceSession(new SessionOptions().ApplyConfiguration("ort_with_npu"));
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n\n");
Thread.Sleep(1000);
});
addOutput(OutputLabel, "Testing successfully completed! See the Console log for more info.");
}
private async void Start_Clicked(object sender, EventArgs e)
{
await ExecuteTests()
.ContinueWith(
(task) =>
{
if (task.IsFaulted)
MainThread.BeginInvokeOnMainThread(() => DisplayAlert("Error", task.Exception.Message, "OK"));
})
.ConfigureAwait(false);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.ML.OnnxRuntime.InferenceSample\Microsoft.ML.OnnxRuntime.InferenceSample.csproj" />
<ProjectReference Include="..\..\..\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Microsoft.ML.OnnxRuntime.InferenceSample.Maui"
x:Class="Microsoft.ML.OnnxRuntime.InferenceSample.Maui.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Maui;
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new AppShell();
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="Microsoft.ML.OnnxRuntime.InferenceSample.Maui.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Microsoft.ML.OnnxRuntime.InferenceSample.Maui"
Shell.FlyoutBehavior="Disabled">
<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />
</Shell>
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Maui;
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Microsoft.ML.OnnxRuntime.InferenceSample.Maui.MainPage">
<StackLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label Text="Inference Sample" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
<Label Text="ONNX Runtime" FontSize="Title" Padding="30,10,30,10"/>
<Button x:Name="Start" Text="Run tests" Clicked="Start_Clicked" FontSize="Large" />
<Label x:Name="OutputLabel" Text="Output" FontSize="Small"/>
</StackLayout>
</ContentPage>
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Maui;
//using Microsoft.Maui.Controls;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
// Best Practice: create the inference session (which loads and optimizes the model) once and not per inference
// as it can be expensive and time consuming.
inferenceSampleApi = new InferenceSampleApi();
}
protected override void OnAppearing()
{
base.OnAppearing();
OutputLabel.Text = "Press 'Run Tests'.\n";
}
private readonly InferenceSampleApi inferenceSampleApi;
private async Task ExecuteTests()
{
Action<Label, string> addOutput = (label, text) =>
{
Application.Current.Dispatcher.Dispatch(() => { label.Text += text; });
//Device.BeginInvokeOnMainThread(() => { label.Text += text; });
Console.Write(text);
};
OutputLabel.Text = "Testing execution\nComplete output is written to Console in this trivial example.\n\n";
// run the testing in a background thread so updates to the UI aren't blocked
await Task.Run(() =>
{
addOutput(OutputLabel, "Testing using default platform-specific session options... ");
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n");
Thread.Sleep(1000); // artificial delay so the UI updates gradually
// demonstrate a range of usages by recreating the inference session with different session options.
addOutput(OutputLabel, "Testing using default platform-specific session options... ");
inferenceSampleApi.CreateInferenceSession(SessionOptionsContainer.Create());
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n");
Thread.Sleep(1000);
addOutput(OutputLabel, "Testing using named platform-specific session options... ");
inferenceSampleApi.CreateInferenceSession(SessionOptionsContainer.Create("ort_with_npu"));
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n");
Thread.Sleep(1000);
addOutput(OutputLabel, "Testing using default platform-specific session options via ApplyConfiguration extension... ");
inferenceSampleApi.CreateInferenceSession(new SessionOptions().ApplyConfiguration());
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n");
Thread.Sleep(1000);
addOutput(OutputLabel, "Testing using named platform-specific session options via ApplyConfiguration extension... ");
inferenceSampleApi.CreateInferenceSession(new SessionOptions().ApplyConfiguration("ort_with_npu"));
inferenceSampleApi.Execute();
addOutput(OutputLabel, "done.\n\n");
Thread.Sleep(1000);
});
addOutput(OutputLabel, "Testing successfully completed! See the Console log for more info.");
}
private async void Start_Clicked(object sender, EventArgs e)
{
await ExecuteTests()
.ContinueWith(
(task) =>
{
if (task.IsFaulted)
MainThread.BeginInvokeOnMainThread(() => DisplayAlert("Error", task.Exception.Message, "OK"));
})
.ConfigureAwait(false);
}
}
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Maui;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
return builder.Build();
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- note net6.0-maccatalyst is not supported currently. requires a new native build to be added. -->
<TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>Microsoft.ML.OnnxRuntime.InferenceSample.Maui</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Display name -->
<ApplicationTitle>InferenceSample_Maui</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.microsoft.ml.onnxruntime.inferencesample.maui</ApplicationId>
<ApplicationIdGuid>58af3884-1c25-42b7-b78b-30a65fb3cf69</ApplicationIdGuid>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
<!-- set ORT SelectedTargets to include .net6 target frameworks -->
<PropertyGroup>
<SelectedTargets>All</SelectedTargets>
</PropertyGroup>
<ItemGroup>
<!-- NOTE:
You need to manually put builds from other platforms such as Android in the correct place for this to work for cross-platform
builds such as running in the Android simulator.
The 'correct' place is defined by the OnnxRuntimeBuildDirectory property in Microsoft.ML.OnnxRuntime.csproj
-->
<ProjectReference Include="..\..\..\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" />
<ProjectReference Include="..\Microsoft.ML.OnnxRuntime.InferenceSample\Microsoft.ML.OnnxRuntime.InferenceSample.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\..\..\testdata\bench.in">
<Link>TestData\bench.in</Link>
</EmbeddedResource>
<EmbeddedResource Include="..\..\..\testdata\squeezenet.onnx">
<Link>TestData\squeezenet.onnx</Link>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31611.283
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.OnnxRuntime.InferenceSample.Maui", "Microsoft.ML.OnnxRuntime.InferenceSample.Maui.csproj", "{00338B12-B291-43A6-9F54-0174660FB70E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00338B12-B291-43A6-9F54-0174660FB70E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00338B12-B291-43A6-9F54-0174660FB70E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00338B12-B291-43A6-9F54-0174660FB70E}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{00338B12-B291-43A6-9F54-0174660FB70E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00338B12-B291-43A6-9F54-0174660FB70E}.Release|Any CPU.Build.0 = Release|Any CPU
{00338B12-B291-43A6-9F54-0174660FB70E}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
\ No newline at end of file
using Android.App;
using Android.Content.PM;
using Android.OS;
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Maui;
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
using Android.App;
using Android.Runtime;
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Maui;
[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>
\ No newline at end of file
using Foundation;
namespace Microsoft.ML.OnnxRuntime.InferenceSample.Maui;
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment