示例#1
0
        public void Infer(GlobalAveragePool layer, GlobalAveragePool2dLayerArgument argument, InferenceContext context)
        {
            var inputAlloc  = context.MainMemoryMap[layer.Input.Connection.From];
            var outputAlloc = context.MainMemoryMap[layer.Output];

            argument.Flags = K210LayerFlags.MainMemoryOutput;
            argument.MainMemoryInputAddress  = inputAlloc.GetAddress();
            argument.MainMemoryOutputAddress = outputAlloc.GetAddress();
        }
示例#2
0
        public GlobalAveragePool2dLayerArgument DeserializeBin(int offset, K210BinDeserializeContext context)
        {
            var sr       = context.GetReaderAt(offset);
            var argument = new GlobalAveragePool2dLayerArgument();

            argument.Flags = sr.Read <K210LayerFlags>();
            argument.MainMemoryInputAddress  = sr.Read <uint>();
            argument.MainMemoryOutputAddress = sr.Read <uint>();
            argument.KernelSize = sr.Read <uint>();
            argument.Channels   = sr.Read <uint>();

            return(argument);
        }
示例#3
0
        public void Forward(GlobalAveragePool2dLayerArgument 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));

            int i = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                float sum = 0;
                for (int x = 0; x < argument.KernelSize; x++)
                {
                    sum += src[i++];
                }
                dest[oc] = sum / argument.KernelSize;
            }
        }