Esempio n. 1
0
        public void Infer(ChannelwiseDequantize layer, ChannelwiseDequantizeLayerArgument 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();
        }
Esempio n. 2
0
        public ChannelwiseDequantizeLayerArgument DeserializeBin(int offset, K210BinDeserializeContext context)
        {
            var sr       = context.GetReaderAt(offset);
            var argument = new ChannelwiseDequantizeLayerArgument
            {
                Flags = sr.Read <K210LayerFlags>(),
                MainMemoryInputAddress  = sr.Read <uint>(),
                MainMemoryOutputAddress = sr.Read <uint>(),
                Channels    = sr.Read <uint>(),
                ChannelSize = sr.Read <uint>()
            };

            argument.QuantParams = sr.ReadArray <K210QuantizationParam>((int)argument.Channels);
            return(argument);
        }
Esempio n. 3
0
        public void Forward(ChannelwiseDequantizeLayerArgument argument, ForwardContext context)
        {
            var src  = context.GetMainRamAt((int)argument.MainMemoryInputAddress);
            var dest = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryOutputAddress));

            int idx = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                var q = argument.QuantParams[oc];
                for (int i = 0; i < argument.ChannelSize; i++)
                {
                    dest[idx] = src[idx] * q.Scale + q.Bias;
                    idx++;
                }
            }
        }