Example #1
0
        public void Infer(layers.Quantize layer, QuantizeLayerArgument 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();
        }
Example #2
0
        public void Forward(QuantizeLayerArgument argument, ForwardContext context)
        {
            var   src   = MemoryMarshal.Cast <byte, float>(context.GetMainRamAt((int)argument.MainMemoryInputAddress));
            var   dest  = context.GetMainRamAt((int)argument.MainMemoryOutputAddress);
            var   q     = argument.QuantParam;
            float scale = 1f / q.Scale;

            for (int i = 0; i < argument.Count; i++)
            {
                int value = (int)Math.Round((src[i] - q.Bias) * scale);
                dest[i] = (byte)FxExtensions.Clamp(value, 0, 0xFF);
            }
        }
Example #3
0
        public QuantizeLayerArgument DeserializeBin(int offset, K210BinDeserializeContext context)
        {
            var sr       = context.GetReaderAt(offset);
            var argument = new QuantizeLayerArgument
            {
                Flags = sr.Read <K210LayerFlags>(),
                MainMemoryInputAddress  = sr.Read <uint>(),
                MainMemoryOutputAddress = sr.Read <uint>(),
                Count      = sr.Read <uint>(),
                QuantParam = sr.Read <K210QuantizationParam>()
            };

            return(argument);
        }