public static async Task <RN1015k500Model> CreateFromStreamAsync(IRandomAccessStreamReference stream) { RN1015k500Model learningModel = new RN1015k500Model(); learningModel.model = await LearningModel.LoadFromStreamAsync(stream); learningModel.session = new LearningModelSession(learningModel.model); learningModel.binding = new LearningModelBinding(learningModel.session); return(learningModel); }
private async void ImagePickerControl_ImagePreviewReceived(object sender, WindowsMLDemos.Common.UI.ImagePreviewReceivedEventArgs e) { try { myMap.Visibility = Visibility.Visible; if (rnModel == null) { var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Model/RN1015k500.onnx")); if (modelFile != null) { rnModel = new RN1015k500Model(); await MLHelper.CreateModelAsync(modelFile, rnModel, true); } } await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { if (e.PreviewImage != null) { var output = await rnModel.EvaluateAsync(new RN1015k500Input { data = ImageFeatureValue.CreateFromVideoFrame(e.PreviewImage)//TensorFloat16Bit.CreateFromArray(new long[] { -1, 3, 224, 224 }, imageData) }) as RN1015k500Output; if (output != null) { var res = output.classLabel.GetAsVectorView().ToArray(); var b = output.softmax_output?.ToList(); if (res.Length > 0) { var locationData = res[0].Split('\t'); var city = locationData[0]; var lat = float.Parse(locationData[1]); var lon = float.Parse(locationData[2]); var sPoint = new Geopoint(new BasicGeoposition { Latitude = lat, Longitude = lon }); Geopoint pointToReverseGeocode = sPoint; // Reverse geocode the specified geographic location. MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode); // If the query returns results, display the name of the town // contained in the address of the first result. if (result.Status == MapLocationFinderStatus.Success) { city = result.Locations[0].DisplayName;// + result.Locations[0].Address.FormattedAddress + result.Locations[0].Address.Country; } myMap.Center = sPoint; myMap.Layers.Add(new MapElementsLayer { ZIndex = 1, MapElements = new List <MapElement>() { new MapIcon { Location = sPoint, NormalizedAnchorPoint = new Windows.Foundation.Point(0.5, 1), ZIndex = 0, Title = city, CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible, Visible = true } } }); } } } }); } catch (Exception ex) { await AlertHelper.ShowMessageAsync(ex.ToString()); } rnModel.Session.Dispose(); rnModel.LearningModel.Dispose(); rnModel = null; }