Exemplo n.º 1
0
        public void Forward(QuantizedResizeNearestNeighborLayerArgument argument, ForwardContext context)
        {
            var src  = context.GetMainRamAt((int)argument.MainMemoryInputAddress);
            var dest = context.GetMainRamAt((int)argument.MainMemoryOutputAddress);

            float heightScale = (float)argument.InputHeight / argument.OutputHeight;
            float widthScale  = (float)argument.InputWidth / argument.OutputWidth;

            int destIdx = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                var channelSrc = src.Slice((int)(argument.InputWidth * argument.InputHeight * oc));
                for (int oy = 0; oy < argument.OutputHeight; oy++)
                {
                    var inY     = (int)Math.Min(Math.Floor(oy * heightScale), argument.InputHeight - 1);
                    var yOrigin = channelSrc.Slice(inY * (int)argument.InputWidth);
                    for (int ox = 0; ox < argument.OutputWidth; ox++)
                    {
                        var inX = (int)Math.Min(Math.Floor(ox * widthScale), argument.InputWidth - 1);
                        dest[destIdx++] = yOrigin[inX];
                    }
                }
            }
        }
        public void Infer(QuantizedResizeNearestNeighbor layer, QuantizedResizeNearestNeighborLayerArgument argument, InferenceContext context)
        {
            var inputAlloc  = context.MainMemoryMap[layer.Input.Connection.From];
            var outputAlloc = context.MainMemoryMap[layer.Output];

            argument.MainMemoryInputAddress  = inputAlloc.GetAddress();
            argument.MainMemoryOutputAddress = outputAlloc.GetAddress();
        }
Exemplo n.º 3
0
        public QuantizedResizeNearestNeighborLayerArgument DeserializeBin(int offset, K210BinDeserializeContext context)
        {
            var sr       = context.GetReaderAt(offset);
            var argument = new QuantizedResizeNearestNeighborLayerArgument
            {
                Flags = sr.Read <K210LayerFlags>(),
                MainMemoryInputAddress  = sr.Read <uint>(),
                MainMemoryOutputAddress = sr.Read <uint>(),
                InputWidth   = sr.Read <uint>(),
                InputHeight  = sr.Read <uint>(),
                Channels     = sr.Read <uint>(),
                OutputWidth  = sr.Read <uint>(),
                OutputHeight = sr.Read <uint>(),
                AlignCorners = sr.Read <int>()
            };

            return(argument);
        }