Beispiel #1
0
        protected override void OnPlanning(GraphPlanContext context)
        {
            var graph    = context.TFGraph;
            var x        = context.TFOutputs[Input.Connection.From];
            var scale    = Scale.ToNHWC();
            var offset   = Offset.ToNHWC();
            var mean     = Mean.ToNHWC();
            var variance = Variance.ToNHWC();

            if (Input.Dimensions.Length == 4)
            {
                context.TFOutputs[Output] = graph.FusedBatchNorm(x, graph.Const(scale), graph.Const(offset), graph.Const(mean), graph.Const(variance), Epsilon, is_training: false).y;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #2
0
        protected override void OnPlanning(GraphPlanContext context)
        {
            var graph    = context.TFGraph;
            var x        = context.TFOutputs[Input.Connection.From];
            var scale    = Scale.ToNHWC();
            var offset   = Offset.ToNHWC();
            var mean     = Mean.ToNHWC();
            var variance = Variance.ToNHWC();

            if (Input.Dimensions.Length == 4)
            {
                context.TFOutputs[Output] = graph.FusedBatchNorm(x, graph.Const(scale), graph.Const(offset), graph.Const(mean), graph.Const(variance), Epsilon, is_training: false).y;
            }
            else
            {
                var y = graph.Sub(x, graph.Const(mean));
                var v = graph.Sqrt(graph.Add(graph.Const(variance), graph.Const(Epsilon)));
                y = graph.RealDiv(y, v);
                y = graph.Mul(y, graph.Const(scale));

                context.TFOutputs[Output] = graph.Add(y, graph.Const(offset));
            }
        }