예제 #1
0
        /// <summary>
        /// Runs prediction until the consecutive, cumulative score matches or goes above the specified threshold.
        /// When a prediction does not match the previous prediction, the counter is reset. To be used with PredictAsync
        /// </summary>
        /// <param name="threshhold">Score to consider</param>
        /// <param name="result">The output CumulativeConfidenceResult to update</param>
        /// <param name="destroyTexture">Optional flag to destroy Texture2D once prediction is finished</param>
        public void CumulativeConfidenceAsync(float threshhold, ref CumulativeConfidenceResult result, bool destroyTexture = false)
        {
            string prevLabel = null;

            if (result.LastResult != null)
            {
                prevLabel = result.LastResult.Best().Label;
            }

            var prediction = GetPredictionResultAsync(destroyTexture);

            if (prediction != null)
            {
                result.LastResult = prediction;
                result.Threshhold = threshhold;

                if (prevLabel != null && prevLabel != prediction.Best().Label)
                {
                    result.CumulativeConfidence = 0;
                }
                else if (result.CumulativeConfidence <= threshhold)
                {
                    result.CumulativeConfidence += prediction.Best().Confidence;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Runs prediction until the consecutive, cumulative score matches or goes above the specified threshold.
        /// When a prediction does not match the previous prediction, the counter is reset.
        /// </summary>
        /// <param name="image">Input Texture2D to predict</param>
        /// <param name="threshhold">Score to consider</param>
        /// <param name="result">The output CumulativeConfidenceResult to update</param>
        public void CumulativeConfidence(Texture2D image, float threshhold, ref CumulativeConfidenceResult result)
        {
            string prevLabel = null;

            if (result.LastResult != null)
            {
                prevLabel = result.LastResult.Best().Label;
            }
            var prediction = Predict(image);

            result.LastResult = prediction;
            result.Threshhold = threshhold;

            if (prevLabel != null && prevLabel != prediction.Best().Label)
            {
                result.CumulativeConfidence = 0;
            }
            else if (result.CumulativeConfidence <= threshhold)
            {
                result.CumulativeConfidence += prediction.Best().Confidence;
            }
        }