Esempio n. 1
0
        public static void Tensors_Constants()
        {
            var t1 = new tf.Tensor(3);
            var t2 = new tf.Tensor("Hello! Tensorflow.NET");
            var nd = new NDArray(new int[] { 3, 1, 1, 2 });
            var t3 = new tf.Tensor(nd);

            Console.WriteLine($"t1: {t1},\nt2: {t2},\nt3: {t3}\n");

            var nd1  = new NDArray(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            var tnd1 = new tf.Tensor(nd1);

            Console.WriteLine($"tnd1: {tnd1}");

            var c1 = tf.constant_op.constant(3);
            var c2 = tf.constant_op.constant(1.0f);
            var c3 = tf.constant_op.constant(2.0);

            Console.WriteLine($"c1: {c1}\nc2: {c2}\nc3: {c3}");

            var nd2 = np.array(new int[, ]
            {
                { 1, 2, 3 },
                { 4, 5, 6 }
            });

            var tensor = tf.constant_op.constant(nd2);

            print($"tensor: {tensor}");
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the index with the largest value across dimensions of a tensor.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="dimension"></param>
        /// <param name="output_type"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Tensor arg_max(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("ArgMax", name, new { input, dimension, output_type });

            return(_op.outputs[0]);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a sequence of numbers.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="limit"></param>
        /// <param name="delta"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Tensor range(Tensor start, Tensor limit, Tensor delta, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("Range", name, new { start, limit, delta });

            return(_op.outputs[0]);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds sparse updates to a variable reference.
        /// </summary>
        /// <param name="ref"></param>
        /// <param name="indices"></param>
        /// <param name="updates"></param>
        /// <param name="use_locking"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Tensor scatter_add(RefVariable @ref, Tensor indices, Tensor updates, bool use_locking = false, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("ScatterAdd", name: name, args: new { @ref, indices, updates, use_locking });

            return(_op.outputs[0]);
        }
Esempio n. 5
0
 public static Tensor destroy_resource_op(Tensor resource, bool ignore_lookup_error = true, string name = null)
 => tf.Context.ExecuteOp("DestroyResourceOp", name,
                         new ExecuteOpArgs(resource).SetAttributes(new { ignore_lookup_error }));
Esempio n. 6
0
 /// <summary>
 /// Standardize input `x` to a unit normal.
 /// </summary>
 /// <param name="x"></param>
 /// <returns></returns>
 private Tensor _z(Tensor x)
 {
     return(tf.divide(tf.sub(x, this._loc), this._scale));
 }
Esempio n. 7
0
 public static int tensor_id(Tensor tensor)
 {
     return(tensor.Id);
 }
Esempio n. 8
0
        /// <summary>
        /// Returns which elements of x are finite.
        /// </summary>
        /// <param name="x"> A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`.</param>
        /// <param name="name"> A name for the operation (optional).</param>
        /// <returns> A `Tensor` of type `bool`.</returns>
        public static Tensor is_finite(Tensor x, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("IsFinite", name, args: new { x });

            return(_op.outputs[0]);
        }
Esempio n. 9
0
 public static Tensor add(Tensor a, Tensor b)
 {
     return(gen_math_ops.add(a, b));
 }
Esempio n. 10
0
 public static Tensor internal_convert_to_tensor_or_composite(Tensor value, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool as_ref = false)
 {
     return(internal_convert_to_tensor(value, dtype: dtype, name: name, as_ref: as_ref));
 }
Esempio n. 11
0
 public static Tensor pow(Tensor x, double y)
 {
     return(gen_math_ops.pow(x, y));
 }
Esempio n. 12
0
 public static Tensor multiply(Tensor x, Tensor y)
 {
     return(gen_math_ops.mul(x, y));
 }
Esempio n. 13
0
 public static Tensor sub(Tensor a, Tensor b)
 {
     return(gen_math_ops.sub(a, b));
 }
Esempio n. 14
0
        public static Tensor add(Tensor x, Tensor y, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("Add", name, args: new { x, y });

            return(_op.outputs[0]);
        }
Esempio n. 15
0
 public static Tensor size(Tensor input,
                           string name          = null,
                           TF_DataType out_type = TF_DataType.TF_INT32) => array_ops.size(input,
                                                                                          name,
                                                                                          optimize: true,
                                                                                          out_type: out_type);
Esempio n. 16
0
        public static Tensor squared_difference(Tensor x, Tensor y, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("SquaredDifference", name, args: new { x, y, name });

            return(_op.outputs[0]);
        }
Esempio n. 17
0
        public static Tensor cast(Tensor x, TF_DataType DstT, bool Truncate = false, string name = "")
        {
            var _op = _op_def_lib._apply_op_helper("Cast", name, args: new { x, DstT, Truncate });

            return(_op.outputs[0]);
        }
Esempio n. 18
0
        /// <summary>
        /// Computes natural logarithm of x element-wise.
        /// </summary>
        /// <param name="x"> A `Tensor`. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`, `complex64`, `complex128`.</param>
        /// <param name="name"> name: A name for the operation (optional).</param>
        /// <returns> A `Tensor`. Has the same type as `x`.</returns>
        public static Tensor log(Tensor x, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("Log", name, args: new { x });

            return(_op.outputs[0]);
        }
Esempio n. 19
0
        public static Tensor floor_div(Tensor x, Tensor y, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("FloorDiv", name, args: new { x, y });

            return(_op.outputs[0]);
        }
Esempio n. 20
0
 /// <summary>
 /// Reads the value of a variable.
 /// </summary>
 /// <param name="resource"></param>
 /// <param name="dtype"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static Tensor read_variable_op(Tensor resource, TF_DataType dtype, string name = null)
 => tf.Context.ExecuteOp("ReadVariableOp", name, new ExecuteOpArgs(resource)
                         .SetAttributes(new { dtype }));
Esempio n. 21
0
        /// <summary>
        /// Multiply the matrix "a" by the matrix "b".
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="transpose_a"></param>
        /// <param name="transpose_b"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Tensor mat_mul(Tensor a, Tensor b, bool transpose_a = false, bool transpose_b = false, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("MatMul", name, args: new { a, b, transpose_a, transpose_b });

            return(_op.outputs[0]);
        }
Esempio n. 22
0
 private Tensor _log_unnormalized_prob(Tensor x)
 {
     return(-0.5 * math_ops.square(_z(x)));
 }
Esempio n. 23
0
        public static Tensor _sum(Tensor input, int axis, bool keep_dims = false, string name = null)
        {
            var _op = _op_def_lib._apply_op_helper("Sum", name, args: new { input, reduction_indices = axis, keep_dims });

            return(_op.outputs[0]);
        }
Esempio n. 24
0
 internal NDArrayTensor Out(Tensorflow.Tensor x)
 {
     return new NDArrayTensor(x);
 }
 public static Tensor reduce_logsumexp(Tensor input_tensor,
                                       int[] axis    = null,
                                       bool keepdims = false,
                                       string name   = null) => math_ops.reduce_logsumexp(input_tensor, axis, keepdims, name);