示例#1
0
        public static Tensor softmax(Tensor logits, string name = null)
        {
            if (tf.context.executing_eagerly())
            {
                var    results = EagerTensorPass.Create();
                var    inputs  = EagerTensorPass.From(logits);
                Status status  = c_api.TFE_FastPathExecute(tf.context, tf.context.device_name,
                                                           "Softmax", name,
                                                           inputs.Points, inputs.Length,
                                                           null, null,
                                                           results.Points, results.Length);
                status.Check(true);
                return(results[0].Resolve());
            }

            var _op = _op_def_lib._apply_op_helper("Softmax", name: name, args: new
            {
                logits
            });

            return(_op.outputs[0]);
        }
示例#2
0
        public Tensor gradient(Tensor target, Tensor source)
        {
            if (_recording)
            {
                if (!_persistent)
                {
                    _pop_tape();
                }
            }

            var results = EagerTensorPass.Create();
            var targets = EagerTensorPass.From(target);
            var sources = EagerTensorPass.From(source);

            Status status = c_api.TFE_TapeGradient(_tape,
                                                   targets.Points, targets.Length,
                                                   sources.Points, sources.Length,
                                                   results.Points, results.Length);

            status.Check(true);

            return(results[0].Resolve());
        }