Ejemplo n.º 1
0
        public ConcreteFunction(Func <Tensor, Tensor> func, TF_DataType dtype)
        {
            string func_name = $"{func.Method.Name}_{ops.uid_function()}";

            func_graph = new FuncGraph(func_name);
            func_graph.as_default();
            var input  = tf.placeholder(dtype);
            var output = func(input);

            var opers = func_graph._nodes_by_name.Values.Select(x => x as Operation).ToArray();

            func_graph.ToGraph(opers,
                               new[] { input },
                               new[] { output },
                               null);
            func_graph.Exit();
        }
Ejemplo n.º 2
0
        public ConcreteFunction(Func <Tensor, IDatasetV2> func, TF_DataType dtype)
        {
            string func_name = $"{func.Method.Name}_{Guid.NewGuid()}";

            func_graph = new FuncGraph(func_name);
            func_graph.as_default();

            var input  = tf.placeholder(dtype);
            var output = func(input);

            OutputStructure = output.structure;

            var opers = func_graph._nodes_by_name.Values.Select(x => x as Operation).ToArray();

            func_graph.ToGraph(opers,
                               new[] { input },
                               new[] { output.variant_tensor },
                               null);
            func_graph.Exit();
        }
Ejemplo n.º 3
0
        public ConcreteFunction(Func <Tensor, Tensor> func, TF_DataType dtype)
        {
            string func_name = $"autograph_{Guid.NewGuid()}_{func.Method.Name}";

            tf.compat.v1.disable_eager_execution();

            // IntPtr func_handle;
            using (var graph = new FuncGraph(func_name))
            {
                graph.as_default();
                var input  = tf.placeholder(dtype);
                var output = func(input);

                var opers = graph._nodes_by_name.Values.Select(x => x as Operation).ToArray();
                _handle = graph.ToGraph(opers,
                                        new Operation[] { input },
                                        new Operation[] { output },
                                        null);
            }

            tf.enable_eager_execution();
        }
Ejemplo n.º 4
0
        public ConcreteFunction(Func <Tensors, Tensors> func,
                                TF_DataType[] dtypes, TensorShape[] shapes)
        {
            string func_name = $"{func.Method.Name}_{Guid.NewGuid()}";

            // IntPtr func_handle;
            using var graph = new FuncGraph(func_name);
            graph.as_default();

            var inputs = new Tensors();

            foreach (var(i, dtype) in enumerate(dtypes))
            {
                inputs.Add(tf.placeholder(dtypes[i], shape: shapes[i], name: "args"));
            }
            Outputs         = func(inputs);
            OutputStructure = Outputs.Select(x => x.ToTensorSpec()).ToArray();

            var opers = graph._nodes_by_name.Values.Select(x => x as Operation).ToArray();

            _handle = graph.ToGraph(opers, inputs, Outputs, null);
            graph.Exit();
        }
Ejemplo n.º 5
0
 public void Enter()
 {
     func_graph.as_default();
 }