public void Forward(ResizeNearestNeighborLayerArgument argument, ForwardContext context) { var src = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress)); var dest = MemoryMarshal.Cast <byte, float>(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(ResizeNearestNeighbor layer, ResizeNearestNeighborLayerArgument 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(); }
public ResizeNearestNeighborLayerArgument DeserializeBin(int offset, K210BinDeserializeContext context) { var sr = context.GetReaderAt(offset); var argument = new ResizeNearestNeighborLayerArgument { 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); }