Ejemplo n.º 1
0
        void _kernel(SpanTensor2 <Pixel.RGB24> src, SpanTensor2 <Pixel.Luminance8> dst)
        {
            // src & dst dimensions must be 512x512

            var workingTensor = _Session.GetInputTensor <float>(0)
                                .AsSpanTensor4()
                                .GetSubTensor(0)
                                .VerifyDimensions(3, 512, 512);

            SpanTensor.Copy(src.DownCast <Byte>(), workingTensor[0], workingTensor[1], workingTensor[2], MultiplyAdd.CreateMul(255).GetInverse());

            // increase image contrast (optional)
            var imagePreprocessor = new ImageProcessor <Pixel.RGB96F>();

            imagePreprocessor.ColorTransform = MultiplyAdd.CreateAdd(-0.5f).ConcatMul(1.7f);

            imagePreprocessor.ColorTransform.ApplyTransformTo(workingTensor.Span);

            _Session.Inference();

            var result = _Session.GetOutputTensor <float>(0)
                         .AsSpanTensor4()
                         .GetSubTensor(0)
                         .VerifyDimensions(1, 512, 512)
                         .GetSubTensor(0);

            SpanTensor.Copy(result, dst.Cast <Byte>(), MultiplyAdd.CreateMul(255));
        }
Ejemplo n.º 2
0
            public FullStackFaceInfo[] Process(SpanBitmap srcImage)
            {
                var workingTensor = _Session.UseInputTensor <Byte>(0, srcImage.Height, srcImage.Width, 3)
                                    .AsSpanTensor3()
                                    .UpCast <Pixel.RGB24>();

                workingTensor.AsSpanBitmap().AsTypeless().SetPixels(0, 0, srcImage);

                _Session.Inference();

                var scores     = _Session.GetOutputTensor <float>(0).VerifyName(n => n == "scores").AsSpanTensor1();
                var bboxes     = _Session.GetOutputTensor <Int64>(1).VerifyName(n => n == "bboxes").AsSpanTensor2();
                var kpss       = _Session.GetOutputTensor <Int64>(2).VerifyName(n => n == "kpss").AsSpanTensor3();
                var align_imgs = _Session.GetOutputTensor <byte>(3).VerifyName(n => n == "align_imgs").AsSpanTensor4().UpCast <Pixel.BGR24>();
                var lmks       = _Session.GetOutputTensor <Int64>(4).VerifyName(n => n == "lmks").AsSpanTensor3();
                var M          = _Session.GetOutputTensor <float>(5).VerifyName(n => n == "M").AsSpanTensor3().UpCast <System.Numerics.Vector3>();

                return(FullStackFaceInfo.Parse(scores, bboxes, align_imgs, lmks));
            }