Ejemplo n.º 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);
        }