コード例 #1
0
        public static async Task <OnnxModel> CreateFromStreamAsync(StorageFile modelFile)
        {
            OnnxModel learningModel = new OnnxModel();

            learningModel.model = await LearningModel.LoadFromStorageFileAsync(modelFile);

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

            var inputFeature = learningModel.model.InputFeatures[0];

            learningModel.inName = inputFeature.Name;

            var inputTensorFeature = inputFeature as TensorFeatureDescriptor;

            learningModel.InWidth  = (int)inputTensorFeature.Shape[3];
            learningModel.InHeight = (int)inputTensorFeature.Shape[2];

            var outputFeature = learningModel.model.OutputFeatures[0];

            learningModel.outName = outputFeature.Name;

            var outputTensorFeature = outputFeature as TensorFeatureDescriptor;

            learningModel.OutWidth  = (int)outputTensorFeature.Shape[3];
            learningModel.OutHeight = (int)outputTensorFeature.Shape[2];

            Debug.Log(string.Format("Input Feature Name: {0}", learningModel.inName));
            Debug.Log(string.Format("Output Feature Name: {0}", learningModel.outName));
            Debug.Log(string.Format("Input Width, Height: {0}, {1}", learningModel.InWidth, learningModel.InHeight));
            Debug.Log(string.Format("Output Width, Height: {0}, {1}", learningModel.OutWidth, learningModel.OutHeight));
            return(learningModel);
        }
コード例 #2
0
        private async Task LoadModelAsync(string modelName)
        {
            var onnx = await StorageFile.GetFileFromApplicationUriAsync(
                new Uri($"ms-appx:///Assets/MLModel/{modelName}.onnx"));

            onnxModel = await OnnxModel.CreateFromStreamAsync(onnx);
        }