Beispiel #1
0
        public void Forward(SoftmaxLayerArgument 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 max = float.MinValue;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                max = Math.Max(max, src[oc]);
            }

            float sum = 0;

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                float value = (float)Math.Exp(src[oc] - max);
                sum     += value;
                dest[oc] = value;
            }

            for (int oc = 0; oc < argument.Channels; oc++)
            {
                dest[oc] /= sum;
            }
        }
Beispiel #2
0
        public void Infer(Softmax layer, SoftmaxLayerArgument 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();
        }
Beispiel #3
0
        public SoftmaxLayerArgument DeserializeBin(int offset, K210BinDeserializeContext context)
        {
            var sr       = context.GetReaderAt(offset);
            var argument = new SoftmaxLayerArgument
            {
                Flags = sr.Read <K210LayerFlags>(),
                MainMemoryInputAddress  = sr.Read <uint>(),
                MainMemoryOutputAddress = sr.Read <uint>(),
                Channels = sr.Read <uint>()
            };

            return(argument);
        }