private async void WinML_Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            //var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/mnist.onnx"));
            var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri($"ms-appx:///Assets/TaxiFareModel.onnx"));

            var learningModel = await LearningModel.LoadFromStreamAsync(modelFile);
        }
Пример #2
0
 public static async Task<ShuffleNetModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
 {
     ShuffleNetModel learningModel = new ShuffleNetModel();
     learningModel.model = await LearningModel.LoadFromStreamAsync(stream);
     learningModel.session = new LearningModelSession(learningModel.model);
     learningModel.binding = new LearningModelBinding(learningModel.session);
     return learningModel;
 }
        public async Task InitializeAsync(ModelType modelType, params string[] parameters)
        {
            var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(parameters[0]));

            model = await LearningModel.LoadFromStreamAsync(file);

            session = new LearningModelSession(model);
            binding = new LearningModelBinding(session);
        }
        public static async Task <FER_Emotion_RecognitionModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            FER_Emotion_RecognitionModel learningModel = new FER_Emotion_RecognitionModel();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
        public static async Task <pointilismModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            pointilismModel learningModel = new pointilismModel();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
        public static async Task <Inceptionv3_convertedModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            Inceptionv3_convertedModel learningModel = new Inceptionv3_convertedModel();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
Пример #7
0
        private static async Task <OnnxModel> CreateFromStreamAsyncHelper(IRandomAccessStreamReference stream)
        {
            OnnxModel onnxModel = new OnnxModel();

            onnxModel.learningModel = await LearningModel.LoadFromStreamAsync(stream);

            onnxModel.session = new LearningModelSession(onnxModel.learningModel);
            onnxModel.binding = new LearningModelBinding(onnxModel.session);
            return(onnxModel);
        }
        public static async Task <MultiObjectDetectionModelv8Model> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            MultiObjectDetectionModelv8Model learningModel = new MultiObjectDetectionModelv8Model();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model, new LearningModelDevice(LearningModelDeviceKind.DirectXHighPerformance));
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
Пример #9
0
        public static async Task <Model> CreateFromStreamAsync(IRandomAccessStreamReference stream, LearningModelDevice deviceToRunOn)
        {
            Model learningModel = new Model();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model, deviceToRunOn);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
Пример #10
0
        public static async Task <TinyYoloV1_2Model> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            var learningModel = new TinyYoloV1_2Model();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
Пример #11
0
        public static async Task <SingelObjectApeModelV8Model> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            SingelObjectApeModelV8Model learningModel = new SingelObjectApeModelV8Model();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
Пример #12
0
        public static async Task <RoadSignDetectionMLModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            RoadSignDetectionMLModel learningModel = new RoadSignDetectionMLModel();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
Пример #13
0
        public static async Task <modelModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            modelModel learningModel = new modelModel();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            learningModel.session = new LearningModelSession(learningModel.model,
                                                             new LearningModelDevice(LearningModelDeviceKind.Default));
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
Пример #14
0
        public static async Task <Model> CreateFromOnnxFilenameAsync(string onnxFilename)
        {
            Model onnxModel = new Model();
            IRandomAccessStreamReference modelFileStream = await StorageFile.GetFileFromPathAsync(onnxFilename);

            onnxModel.learningModel = await LearningModel.LoadFromStreamAsync(modelFileStream);

            onnxModel.session = new LearningModelSession(onnxModel.learningModel);
            onnxModel.binding = new LearningModelBinding(onnxModel.session);

            return(onnxModel);
        }
Пример #15
0
        public static async Task <ScoringModel> CreateFromStreamAsync(IRandomAccessStreamReference stream, bool UseGpu = false)
        {
            ScoringModel learningModel = new ScoringModel();

            learningModel.model = await AsAsync(LearningModel.LoadFromStreamAsync(stream));

            var device = new LearningModelDevice(UseGpu ? LearningModelDeviceKind.DirectXHighPerformance : LearningModelDeviceKind.Cpu);

            learningModel.session = new LearningModelSession(learningModel.model, device);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
    public static async Task <CustomNetworkModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
    {
        // Run on the GPU
        //var device = new LearningModelDevice(LearningModelDeviceKind.DirectX);

        CustomNetworkModel learningModel = new CustomNetworkModel();

        learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

        //learningModel.session = new LearningModelSession(learningModel.model, device);
        learningModel.session = new LearningModelSession(learningModel.model);
        learningModel.binding = new LearningModelBinding(learningModel.session);
        return(learningModel);
    }
Пример #17
0
        public static async Task <classifierModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            classifierModel learningModel = new classifierModel();

            learningModel.model = await LearningModel.LoadFromStreamAsync(stream);

            // Select GPU or another DirectX device to evaluate the model.
            LearningModelDevice device = new LearningModelDevice(LearningModelDeviceKind.DirectX);

            // Create the evaluation session with the model and device.
            learningModel.session = new LearningModelSession(learningModel.model, device);
            learningModel.binding = new LearningModelBinding(learningModel.session);
            return(learningModel);
        }
        /// <summary>
        /// init a ML model
        /// </summary>
        /// <param name="file"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public async static Task CreateModelAsync(StorageFile file, IMachineLearningModel learningModel, bool _useCPU = false)
        {
            LearningModelDevice device = null;

            if (_useCPU)
            {
                device = new LearningModelDevice(LearningModelDeviceKind.Default);
            }
            else
            {
                device = new LearningModelDevice(LearningModelDeviceKind.DirectXHighPerformance);
            }
            learningModel.LearningModel = await LearningModel.LoadFromStreamAsync(file);

            learningModel.Session = new LearningModelSession(learningModel.LearningModel, device);
            learningModel.Binding = new LearningModelBinding(learningModel.Session);
        }
Пример #19
0
        public static async Task <MLModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
        {
            var device = new LearningModelDevice(LearningModelDeviceKind.Cpu);

            var model = new MLModel();
            var load  = LearningModel.LoadFromStreamAsync(stream);

            while (load.Status != Windows.Foundation.AsyncStatus.Completed)
            {
                Thread.Sleep(100);
            }
            model._model = load.GetResults();

            model._session = new LearningModelSession(model._model, device);
            model._binding = new LearningModelBinding(model._session);

            return(model);
        }
Пример #20
0
    public async Task LoadModelAsync(bool shouldUseGpu, bool resourceLoad)
    {
        try
        {
            // Parse labels from label file
            var labelsTextAsset = Resources.Load(LabelsFileName) as TextAsset;
            using (var streamReader = new StringReader(labelsTextAsset.text))
            {
                string line       = "";
                char[] charToTrim = { '\"', ' ' };
                while (streamReader.Peek() >= 0)
                {
                    line = streamReader.ReadLine();
                    line.Trim(charToTrim);
                    var indexAndLabel = line.Split(':');
                    if (indexAndLabel.Count() == 2)
                    {
                        _labels.Add(indexAndLabel[1]);
                    }
                }
            }

#if ENABLE_WINMD_SUPPORT
            if (resourceLoad)
            {
                // Load from Unity Resources via awkward UWP streams and initialize model
                using (var modelStream = new InMemoryRandomAccessStream())
                {
                    var dataWriter    = new DataWriter(modelStream);
                    var modelResource = Resources.Load(ModelFileName) as TextAsset;
                    dataWriter.WriteBytes(modelResource.bytes);
                    await dataWriter.StoreAsync();

                    var randomAccessStream = RandomAccessStreamReference.CreateFromStream(modelStream);

                    _model = await LearningModel.LoadFromStreamAsync(randomAccessStream);

                    var deviceKind = shouldUseGpu ? LearningModelDeviceKind.DirectXHighPerformance : LearningModelDeviceKind.Cpu;
                    _session = new LearningModelSession(_model, new LearningModelDevice(deviceKind));
                }
            }
            else
            {
                try
                {
                    var modelFile = await StorageFile.GetFileFromApplicationUriAsync(
                        new Uri($"ms-appx:///Data/StreamingAssets/SqueezeNet.onnx"));

                    _model = await LearningModel.LoadFromStorageFileAsync(modelFile);

                    var deviceKind = shouldUseGpu ? LearningModelDeviceKind.DirectXHighPerformance : LearningModelDeviceKind.Cpu;
                    _session = new LearningModelSession(_model, new LearningModelDevice(deviceKind));
                }
                catch (Exception e)
                {
                    var exceptionStr = e.ToString();
                    //StatusBlock.text = exceptionStr;
                }
            }

            // Get model input and output descriptions
            var inputImageDescription =
                _model.InputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Image)
                as ImageFeatureDescriptor;
            // Check if input is passed as image if not try to interpret it as generic tensor
            if (inputImageDescription != null)
            {
                InputWidth  = inputImageDescription.Width;
                InputHeight = inputImageDescription.Height;
            }
            else
            {
                var inputTensorDescription =
                    _model.InputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Tensor)
                    as TensorFeatureDescriptor;
                InputWidth  = (uint)inputTensorDescription.Shape[3];
                InputHeight = (uint)inputTensorDescription.Shape[2];
            }

            _outputDescription =
                _model.OutputFeatures.FirstOrDefault(feature => feature.Kind == LearningModelFeatureKind.Tensor)
                as TensorFeatureDescriptor;
#endif
        }
        catch
        {
#if ENABLE_WINMD_SUPPORT
            _model = null;
#endif
            throw;
        }
    }