/// <summary>
        /// Runs the input through the CoreML model
        /// </summary>
        /// <param name="input">The input data to the model.</param>
        /// <returns>The output of the CoreML model.</returns>
        private MLMultiArray Predict(MLMultiArray input)
        {
            var inputFeatureProvider = new ImageInputFeatureProvider(inputFeatureName)
            {
                ImagePixelData = input
            };

            MLMultiArray result = this.mlModel.GetPrediction(inputFeatureProvider, out NSError modelErr)
                                  .GetFeatureValue(outputFeatureName)
                                  .MultiArrayValue;

            return(result);
        }
Example #2
0
        /// <summary>
        /// Extract the direct output from MLCore without post-processing
        /// </summary>
        /// <returns>A tuple contain the two matrices output by the model. First matrix: the box prediction encoding; second matrix: the class logit for each box.</returns>
        /// <param name="input"> The formatted matrix representation of image after proper transpose and normalization</param>
        private (MLMultiArray, MLMultiArray) RawPredict(MLMultiArray input)
        {
            var inputFeatureProvider = new ImageInputFeatureProvider(_inputFeatureName)
            {
                ImagePixelData = input
            };
            var resultBundle = _mlModel.GetPrediction(inputFeatureProvider, out _);
            var output1      = resultBundle.GetFeatureValue(Constants.ModelOutputBoxFeatureName).MultiArrayValue;
            var output2      = resultBundle.GetFeatureValue(Constants.ModelOutputClassFeatureName).MultiArrayValue;

            inputFeatureProvider.Dispose();

            return(output1, output2);
        }