Ejemplo n.º 1
0
        private void RunGraphsAndCompareOutputs(TF_Output[] grad_outputs, TF_Output[] expected_grad_outputs)
        {
            var csession          = new CSession(graph_, s_);
            var expected_csession = new CSession(expected_graph_, s_);

            var grad_outputs_vec = new List <IntPtr>();

            grad_outputs_vec.AddRange(grad_outputs.Select(x => x.oper));
            csession.SetOutputs(grad_outputs_vec);
            csession.Run(s_);
            ASSERT_EQ(TF_OK, TF_GetCode(s_));
            var out0 = csession.output_tensor(0);
            var out1 = csession.output_tensor(1);

            var expected_grad_outputs_vec = new List <IntPtr>();

            expected_grad_outputs_vec.AddRange(expected_grad_outputs.Select(x => x.oper));
            expected_csession.SetOutputs(expected_grad_outputs_vec);
            expected_csession.Run(s_);
            ASSERT_EQ(TF_OK, TF_GetCode(s_));
            var expected_out0 = expected_csession.output_tensor(0);
            var expected_out1 = expected_csession.output_tensor(1);

            //CompareTensors(out0, expected_out0);
            //CompareTensors(out1, expected_out1);
        }
Ejemplo n.º 2
0
        private void RunGraphsAndCompareOutputs(TF_Output[] grad_outputs, TF_Output[] expected_grad_outputs)
        {
            var csession          = new CSession(graph_, s_);
            var expected_csession = new CSession(expected_graph_, s_);

            var grad_outputs_vec = grad_outputs;

            csession.SetOutputs(grad_outputs_vec);
            csession.Run(s_);
            ASSERT_EQ(TF_OK, TF_GetCode(s_));
            var out0 = csession.output_tensor(0);
            var out1 = csession.output_tensor(1);

            var expected_grad_outputs_vec = expected_grad_outputs;

            expected_csession.SetOutputs(expected_grad_outputs_vec);
            expected_csession.Run(s_);
            ASSERT_EQ(TF_OK, TF_GetCode(s_));
            var expected_out0 = expected_csession.output_tensor(0);
            var expected_out1 = expected_csession.output_tensor(1);

            //CompareTensors(out0, expected_out0);
            //CompareTensors(out1, expected_out1);
        }
Ejemplo n.º 3
0
        public void Session()
        {
            lock (Locks.ProcessWide)
            {
                var s     = new Status();
                var graph = new Graph().as_default();

                // Make a placeholder operation.
                var feed = c_test_util.Placeholder(graph, s);

                // Make a constant operation with the scalar "2".
                var two = c_test_util.ScalarConst(2, graph, s);

                // Add operation.
                var add = c_test_util.Add(feed, two, graph, s);

                var csession = new CSession(graph, s);
                ASSERT_EQ(TF_Code.TF_OK, s.Code);

                // Run the graph.
                var inputs = new Dictionary <Operation, Tensor>();
                inputs.Add(feed, new Tensor(3));
                csession.SetInputs(inputs);

                var outputs = new TF_Output[] { new TF_Output(add, 0) };
                csession.SetOutputs(outputs);

                csession.Run(s);
                Tensor outTensor = csession.output_tensor(0);
                EXPECT_EQ(TF_DataType.TF_INT32, outTensor.dtype);
                EXPECT_EQ(0, outTensor.NDims);
                ASSERT_EQ((ulong)sizeof(uint), outTensor.bytesize);
                var output_contents = outTensor.ToArray <int>();
                EXPECT_EQ(3 + 2, output_contents[0]);

                // Add another operation to the graph.
                var neg = c_test_util.Neg(add, graph, s);
                ASSERT_EQ(TF_Code.TF_OK, s.Code);

                // Run up to the new operation.
                inputs = new Dictionary <Operation, Tensor>();
                inputs.Add(feed, new Tensor(7));
                csession.SetInputs(inputs);
                outputs = new TF_Output[] { new TF_Output(neg, 0) };
                csession.SetOutputs(outputs);
                csession.Run(s);
                ASSERT_EQ(TF_Code.TF_OK, s.Code);

                outTensor = csession.output_tensor(0);
                ASSERT_TRUE(outTensor != IntPtr.Zero);
                EXPECT_EQ(TF_DataType.TF_INT32, outTensor.dtype);
                EXPECT_EQ(0, outTensor.NDims); // scalar
                ASSERT_EQ((ulong)sizeof(uint), outTensor.bytesize);
                output_contents = outTensor.ToArray <int>();
                EXPECT_EQ(-(7 + 2), output_contents[0]);

                // Clean up
                csession.CloseAndDelete(s);
                ASSERT_EQ(TF_Code.TF_OK, s.Code);
            }
        }