public static void FitInputImage(this IModelSession session, PointerBitmap bmp)
 {
     if (session.GetInputTensor(0) is IInputImageTensor inputImage)
     {
         inputImage.FitPixels(bmp);
     }
 }
Beispiel #2
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));
        }