// // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); #if !__NATIVE_DEPENDENCIES_EXIST__ throw new System.Exception( "The requisite onnxruntime.framework file(s) were not found. " + "You must build the native iOS components before running this sample"); #else // Register default session options configuration. SessionOptionsContainer.Register((sessionOptions) => { sessionOptions.LogId = "Ort"; }); // Register a named session options configuration that enables the CoreML EP SessionOptionsContainer.Register("ort_with_npu", (sessionOptions) => { sessionOptions.AppendExecutionProvider_CoreML(CoreMLFlags.COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE); options.LogId = "Ort+CoreML"; }); LoadApplication(new App()); #endif #pragma warning disable CS0162 // Unreachable code detected return(base.FinishedLaunching(app, options)); #pragma warning restore CS0162 // Unreachable code detected }
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."); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); // Register default session options configuration. This is optional. SessionOptionsContainer.Register((options) => { options.LogId = "Ort"; }); // Register a named session options configuration that enables NNAPI SessionOptionsContainer.Register("ort_with_npu", (options) => { options.AppendExecutionProvider_Nnapi(); options.LogId = "Ort+Nnapi"; }); LoadApplication(new App()); }