コード例 #1
0
        /// <inheritdoc />
        /// <exception cref="ArgumentNullException">
        /// <paramref name="sources"/> is <b>null</b>.
        /// </exception>
        public IList <Answer> Recognize(IList <ImageSource> sources, CancellationToken cancellationToken)
        {
            if (sources == null)
            {
                throw new ArgumentNullException(nameof(sources));
            }

            // create input tensor
            Tensor x = ImageExtensions.FromImages(
                sources,
                source => source.Image,
                "checkbox",
                this.network.InputShape.Format,
                this.network.InputShape.GetAxis(Axis.X),
                this.network.InputShape.GetAxis(Axis.Y));

            // recognize the image
            IList <IList <(string Answer, float Probability)> > results = this.network.Execute(x).Answers;

            // create the answers
            List <Answer> answers = new List <Answer>(sources.Count);

            for (int i = 0, ii = results.Count; i < ii; i++)
            {
                answers.Add(CheckboxReader.CreateAnswer(sources[i], results[i]));
            }

            return(answers);
        }
コード例 #2
0
        /// <inheritdoc />
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source"/> is <b>null</b>.
        /// </exception>
        public Answer Recognize(ImageSource source, CancellationToken cancellationToken)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            // create input tensor
            Tensor x = ImageExtensions.FromImage(
                source.Image,
                "checkbox",
                this.network.InputShape.Format,
                this.network.InputShape.GetAxis(Axis.X),
                this.network.InputShape.GetAxis(Axis.Y));

            // recognize the image
            IList <(string Answer, float Probability)> result = this.network.Execute(x).Answers[0];

            // create the answer
            return(CheckboxReader.CreateAnswer(source, result));
        }