public float[] EncodeAudio(string audioFile)
        {
            Bitmap bitmap = melgram.Convert(audioFile, 48);

            TFTensor imageTensor = TensorUtils.GetImageTensor(bitmap, melgram.Width, melgram.Height);

            /*
             * foreach(TFOperation op in graph.GetEnumerator())
             * {
             *  if (op != null)
             *  {
             *      Console.WriteLine(op.Name);
             *  }
             * }*/
            var session = new TFSession(graph);
            var runner  = session.GetRunner();

            runner.AddInput(graph["conv2d_1_input"][0], imageTensor);
            runner.Fetch(graph["output_node0"][0]);

            var output = runner.Run();

            // Fetch the results from output:
            TFTensor result = output[0];

            var rshape = result.Shape;

            if (result.NumDims != 2 || rshape[0] != 1)
            {
                var shape = "";
                foreach (var d in rshape)
                {
                    shape += $"{d} ";
                }
                shape = shape.Trim();
                Console.WriteLine($"Error: expected to produce a [1 N] shaped tensor where N is the number of labels, instead it produced one with shape [{shape}]");
                Environment.Exit(1);
            }


            bool jagged = true;

            if (jagged)
            {
                return(((float[][])result.GetValue(jagged: true))[0]);
            }
            else
            {
                var     val           = (float[, ])result.GetValue(jagged: false);
                float[] probabilities = new float[val.GetLength(1)];
                for (int i = 0; i < val.GetLength(1); i++)
                {
                    probabilities[i] = val[0, i];
                }
                return(probabilities);
            }
        }
Exemplo n.º 2
0
        public double[][] predict(double[][] input)
        {
            double[] buffer = new double[input.Length * inputDimension];

            for (int i = 0; i < input.Length; i++)
            {
                for (int j = 0; j < inputDimension; j++)
                {
                    buffer[i * inputDimension + j] = input[i][j];
                }
            }

            var inputShape = new TFShape(new long[] { input.Length, inputDimension });

            TFTensor tfInput = TFTensor.FromBuffer(inputShape, buffer, 0, input.Length * inputDimension);

            TFTensor[] output = session
                                .GetRunner()
                                .AddInput("input_node", tfInput)
                                .Fetch("prediction_node_2")
                                .Run();

            TFTensor theFirstAndOnlyFetchedNode = output[0];
            bool     jagged = true;
            object   native_array_representation = theFirstAndOnlyFetchedNode.GetValue(jagged); // when jagged = true, returning expected dimensions of return

            double[][] typed = (double[][])native_array_representation;                         // typing to expected array with expected dimensions
            return(typed);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            using (TFGraph graph = new TFGraph())
            {
                graph.Import(File.ReadAllBytes(@"C:\Users\Ben\Desktop\frozen.pb"));

                TFSession        session = new TFSession(graph);
                TFSession.Runner runner  = session.GetRunner();

                float[] x1 = new float[] { 239, 958, 8, 34, 239 };
                float[] x2 = new float[] { 239, 958, 8, 34, 239 };
                float[] x3 = new float[] { 239, 958, 8, 34, 239 };

                TFTensor x = new TFTensor(new float[][] { x1, x2, x3 });

                runner.AddInput(graph["Placeholder"][0], x);
                runner.Fetch(graph["add"][0]);

                var output = runner.Run();

                TFTensor result = output[0];

                var v = result.GetValue();

                return;
            }
        }
Exemplo n.º 4
0
        public override string Execute(string input)
        {
            var    inputdict   = JsonConvert.DeserializeObject <Dictionary <string, string> >(input);
            float  conf        = -1.0f;
            string strSentence = inputdict["sentence"];

            var sentence_node    = _graph[_prefix + "/" + "sentence"];
            var is_training_node = _graph[_prefix + "/" + "is_training"];
            var sm_decision_node = _graph[_prefix + "/" + "sm_decision"];

            var runner = _session.GetRunner();

            int[][] sentenceTensor = new int[1][];
            sentenceTensor[0] = IndexText(strSentence);
            TFTensor sentence = new TFTensor(sentenceTensor);

            runner.AddInput(sentence_node[0], sentence);
            runner.AddInput(is_training_node[0], new TFTensor(false));
            runner.Fetch(sm_decision_node[0]);

            var output = runner.Run();

            // Fetch the results from output:
            TFTensor result = output[0];
            object   o      = result.GetValue();

            conf = ((float[, ])o)[0, 1];
            return(string.Format("{{ conf: {0:N2} }}", conf));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Make a prediction for a input image
        /// </summary>
        /// <param name="image">the input image</param>
        /// <returns></returns>
        public int Predict(float[,] im)
        {
            float[] image = TransformArray(im);
            //create a runner with the session
            var runner = _session.GetRunner();

            // create tensor using image
            var tensor = TFTensor.FromBuffer(new TFShape(1, 30, 30, 1), image, 0, image.Length);

            // set inputput layer
            runner.AddInput(_session.Graph[INPUT_NAME][0], tensor);

            // set output layer
            runner.Fetch(_session.Graph[OUTPUT_NAME][0]);

            // run the model
            var output = runner.Run();

            // Get output tensor
            TFTensor result = output[0];

            // get result from tensor
            var resultArray = result.GetValue() as float[, ];

            //return
            return(ExtractPrediction(resultArray));
        }
Exemplo n.º 6
0
        private float[] ExtractFeatures(Bitmap candidate)
        {
            var tensor  = ImageUtil.CreateTensorFromBitmap(candidate);
            var session = new TFSession(_graph);
            var runner  = session.GetRunner();

            runner.AddInput(_graph["input_2"][0], tensor);
            runner.Fetch(_graph["mixed8/concat"][0]);

            var output = runner.Run();

            TFTensor result = output[0];

            var features = (float[, , , ])result.GetValue(jagged: false);

            //features shape: [1,4,4,1280]
            float[] flattenFeatures = new float[20480];
            int     n = 0;

            for (int k = 0; k < 1280; k++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        flattenFeatures[n] = features[0, j, i, k];
                        n++;
                    }
                }
            }
            return(flattenFeatures);
        }
Exemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            //int val1=Int32.Parse(textBox1.Text);
            //int val2 = Int32.Parse(textBox2.Text);
            //var sess = new TFSession();
            //var tf = sess.Graph;
            //var a = tf.Const(val1);
            //var b = tf.Const(val2);
            //label1.Text = sess.GetRunner().Run(tf.Add(a, b)).GetValue().ToString();
            //sess.CloseSession();
            using (var graph = new TFGraph())
            {
                var file = File.ReadAllBytes(@"..\..\python\tmp\model\output.pb");
                graph.Import(file);

                var tf     = new TFSession(graph);
                var runner = tf.GetRunner();
                if (img_tensor != null)
                {
                    runner.AddInput(graph["input"][0], img_tensor);
                    runner.Fetch(graph["output"][0]);
                    var      output = runner.Run();
                    TFTensor result = output[0];


                    label1.Text = "Prediction:\n" + ((System.Int64[])result.GetValue())[0].ToString();
                }
            }
        }
Exemplo n.º 8
0
        public static string Predict(byte[] bytes)
        {
            var img_tensor = FormatJPEG(bytes);

            if (img_tensor != null)
            {
                var runner = tf.GetRunner();
                runner.AddInput(opInput, img_tensor);
                runner.Fetch(opDenseDecode);
                var           output       = runner.Run();
                TFTensor      result       = output[0];
                StringBuilder stringBuffer = new StringBuilder();

                foreach (int s in (System.Int64[, ])result.GetValue())
                {
                    if (s > charset.Count - 1)
                    {
                        Console.WriteLine("Current character set do not match the model.");
                        break;
                    }
                    stringBuffer.Append(charset[s]);
                }
                return(stringBuffer.ToString());
            }
            Console.WriteLine("Imgage error!");
            return(null);
        }
Exemplo n.º 9
0
 public void SetBoolTensor()
 {
     using (var tensor = new TFTensor(true))
     {
         tensor.SetValue(false);
         Assert.Equal((uint)sizeof(bool), tensor.TensorByteSize.ToUInt32());
         Assert.Equal(false, tensor.GetValue());
     }
 }
Exemplo n.º 10
0
 public void SetIntTensor()
 {
     using (var tensor = new TFTensor(123))
     {
         tensor.SetValue(234);
         Assert.Equal((uint)sizeof(int), tensor.TensorByteSize.ToUInt32());
         Assert.Equal(234, tensor.GetValue());
     }
 }
Exemplo n.º 11
0
 public void SetArrayTensor()
 {
     using (var tensor = new TFTensor(new [] { 123, 456 }))
     {
         tensor.SetValue(new [] { 234, 567 });
         Assert.Equal((uint)sizeof(int) * 2, tensor.TensorByteSize.ToUInt32());
         Assert.Equal(new [] { 234, 567 }, tensor.GetValue());
     }
 }
Exemplo n.º 12
0
 public void SetLongTensor()
 {
     using (var tensor = new TFTensor(123L))
     {
         tensor.SetValue(234L);
         Assert.Equal((uint)sizeof(long), tensor.TensorByteSize.ToUInt32());
         Assert.Equal(234L, tensor.GetValue());
     }
 }
Exemplo n.º 13
0
 public void SetComplexTensor()
 {
     using (var tensor = new TFTensor(new Complex(1, 2)))
     {
         tensor.SetValue(new Complex(2, -1));
         Assert.Equal((uint)16, tensor.TensorByteSize.ToUInt32());
         Assert.Equal(new Complex(2, -1), tensor.GetValue());
     }
 }
Exemplo n.º 14
0
 public void SetFloatTensor()
 {
     using (var tensor = new TFTensor(123.456f))
     {
         tensor.SetValue(234.567f);
         Assert.Equal((uint)sizeof(float), tensor.TensorByteSize.ToUInt32());
         Assert.Equal(234.567f, tensor.GetValue());
     }
 }
Exemplo n.º 15
0
 public void SetDoubleTensor()
 {
     using (var tensor = new TFTensor(123.456))
     {
         tensor.SetValue(234.567);
         Assert.Equal((uint)sizeof(double), tensor.TensorByteSize.ToUInt32());
         Assert.Equal(234.567, tensor.GetValue());
     }
 }
Exemplo n.º 16
0
 public void SetUnsignedShortTensor()
 {
     using (var tensor = new TFTensor((ushort)123))
     {
         tensor.SetValue((ushort)234);
         Assert.Equal((uint)sizeof(ushort), tensor.TensorByteSize.ToUInt32());
         Assert.Equal((ushort)234, tensor.GetValue());
     }
 }
Exemplo n.º 17
0
 public void SetSignedByteTensor()
 {
     using (var tensor = new TFTensor((sbyte)123))
     {
         tensor.SetValue((sbyte)-123);
         Assert.Equal((uint)sizeof(sbyte), tensor.TensorByteSize.ToUInt32());
         Assert.Equal((sbyte)-123, tensor.GetValue());
     }
 }
Exemplo n.º 18
0
        public void CreateTenso()
        {
            // Some input matrices


            var inp = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 35, 55, 82, 115, 135, 140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63, 77, 91, 106, 122, 136, 138, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 103, 95, 107, 121, 131, 131, 111, 90, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 111, 112, 101, 91, 102, 121, 126, 126, 108, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 101, 107, 96, 88, 90, 108, 125, 130, 138, 173, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 102, 98, 88, 91, 96, 101, 120, 138, 146, 185, 243, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 96, 93, 91, 92, 98, 111, 135, 153, 172, 221, 242, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 91, 93, 100, 107, 125, 153, 185, 210, 226, 237, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126, 131, 140, 163, 188, 206, 216, 223, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 180, 188, 196, 202, 208, 216, 246, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 203, 203, 193, 200, 210, 233, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 227, 232, 222, 216, 231, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 233, 247, 242, 236, 246, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 151, 155, 0, 183, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            Debug.WriteLine("TEST");
            for (int i = 0; i < inp.Length; i++)
            {
                if (inp[i] == 0)
                {
                    inp[i] = 255;
                }

                // inp[i] = inp[i] / 255;

                //Debug.WriteLine(inp[i]);
            }
            // Debug.WriteLine("len : " + inp.Length);

            var tensor = TFTensor.FromBuffer(new TFShape(1, 30, 30, 1), inp, 0, inp.Length);

            // Debug.WriteLine("input: " + tensor);

            using (var graph = new TFGraph())
            {
                // Load the model
                //  graph.Import(File.ReadAllBytes(@"C:\Users\Public\TestFolder\my_model.pb"));
                string model_file = Path.Combine(Environment.CurrentDirectory, @"model\gesture_model.pb");

                Debug.WriteLine("file path " + model_file);
                graph.Import(File.ReadAllBytes(model_file));


                using (var session = new TFSession(graph))
                {
                    var runner = session.GetRunner();
                    //Debug.WriteLine(graph);
                    runner.AddInput(graph[INPUT_NAME][0], tensor);
                    runner.Fetch(graph[OUTPUT_NAME][0]);
                    Debug.WriteLine(System.DateTime.Now);

                    var      output = runner.Run();
                    TFTensor result = output[0];
                    var      re     = result.GetValue() as float[, ];
                    foreach (float f in re)
                    {
                        Debug.WriteLine(f);
                    }
                    Debug.WriteLine("o: " + re[0, 1]);
                    Debug.WriteLine(result);
                    Debug.WriteLine(System.DateTime.Now);
                }
            }
        }
Exemplo n.º 19
0
        public void ConstructLongTensor()
        {
            long value = 123L;

            using (var tensor = new TFTensor(value))
            {
                Assert.Equal(TFDataType.Int64, tensor.TensorType);
                Assert.Equal(0, tensor.NumDims);
                Assert.Equal(new long [0], tensor.Shape);
                Assert.Equal((uint)sizeof(long), tensor.TensorByteSize.ToUInt32());
                Assert.Equal(value, tensor.GetValue());
            }
        }
Exemplo n.º 20
0
        public void GetArrayValueInPlace(Array array)
        {
            using (var tensor = new TFTensor(array))
            {
                var type  = array.GetType().GetElementType();
                var value = Array.CreateInstance(type, tensor.Shape);
                Assert.NotEqual(array, value);

                tensor.GetValue(value);

                Assert.Equal(array, value);
            }
        }
Exemplo n.º 21
0
        public void ConstructComplexTensor()
        {
            Complex value = new Complex(1, 2);

            using (var tensor = new TFTensor(value))
            {
                Assert.Equal(TFDataType.Complex128, tensor.TensorType);
                Assert.Equal(0, tensor.NumDims);
                Assert.Equal(new long [0], tensor.Shape);
                Assert.Equal(16u, tensor.TensorByteSize.ToUInt32());
                Assert.Equal(value, tensor.GetValue());
            }
        }
Exemplo n.º 22
0
        public void ConstructFloatTensor()
        {
            float value = 123.456f;

            using (var tensor = new TFTensor(value))
            {
                Assert.Equal(TFDataType.Float, tensor.TensorType);
                Assert.Equal(0, tensor.NumDims);
                Assert.Equal(new long [0], tensor.Shape);
                Assert.Equal((uint)sizeof(float), tensor.TensorByteSize.ToUInt32());
                Assert.Equal(value, tensor.GetValue());
            }
        }
Exemplo n.º 23
0
        public void ConstructDoubleTensor()
        {
            double value = 123.456;

            using (var tensor = new TFTensor(value))
            {
                Assert.Equal(TFDataType.Double, tensor.TensorType);
                Assert.Equal(0, tensor.NumDims);
                Assert.Equal(new long [0], tensor.Shape);
                Assert.Equal((uint)sizeof(double), tensor.TensorByteSize.ToUInt32());
                Assert.Equal(value, tensor.GetValue());
            }
        }
Exemplo n.º 24
0
        public void ConstructBoolTensor()
        {
            bool value = true;

            using (var tensor = new TFTensor(value))
            {
                Assert.Equal(TFDataType.Bool, tensor.TensorType);
                Assert.Equal(0, tensor.NumDims);
                Assert.Equal(new long [0], tensor.Shape);
                Assert.Equal((uint)sizeof(bool), tensor.TensorByteSize.ToUInt32());
                Assert.Equal(value, tensor.GetValue());
            }
        }
Exemplo n.º 25
0
        public void ConstructUnsignedShortTensor()
        {
            ushort value = 123;

            using (var tensor = new TFTensor(value))
            {
                Assert.Equal(TFDataType.UInt16, tensor.TensorType);
                Assert.Equal(0, tensor.NumDims);
                Assert.Equal(new long [0], tensor.Shape);
                Assert.Equal((uint)sizeof(ushort), tensor.TensorByteSize.ToUInt32());
                Assert.Equal(value, tensor.GetValue());
            }
        }
Exemplo n.º 26
0
 public void SetMultiDimArrayTensorWithJagged()
 {
     using (var tensor = new TFTensor(new [, ] {
         { 123, 456 }
     }))
     {
         tensor.SetValue(new [] { new [] { 234, 567 } });
         Assert.Equal((uint)sizeof(int) * 2, tensor.TensorByteSize.ToUInt32());
         Assert.Equal(new [, ] {
             { 234, 567 }
         }, tensor.GetValue());
     }
 }
Exemplo n.º 27
0
        public void ConstructSignedByteTensor()
        {
            sbyte value = 123;

            using (var tensor = new TFTensor(value))
            {
                Assert.Equal(TFDataType.Int8, tensor.TensorType);
                Assert.Equal(0, tensor.NumDims);
                Assert.Equal(new long [0], tensor.Shape);
                Assert.Equal((uint)sizeof(sbyte), tensor.TensorByteSize.ToUInt32());
                Assert.Equal(value, tensor.GetValue());
            }
        }
Exemplo n.º 28
0
        public void ConstrucComplexArrayTensor()
        {
            var array = new [] { new Complex(1, 2), new Complex(2, -1) };

            using (var tensor = new TFTensor(array))
            {
                Assert.Equal(TFDataType.Complex128, tensor.TensorType);
                Assert.Equal(array.Rank, tensor.NumDims);
                Assert.Equal(array.Length, tensor.GetTensorDimension(0));
                Assert.Equal(new long [] { array.Length }, tensor.Shape);
                Assert.Equal(16u * array.Length, tensor.TensorByteSize.ToUInt32());
                Assert.Equal(array, tensor.GetValue());
            }
        }
Exemplo n.º 29
0
        public void ConstructUnsignedShortArrayTensor()
        {
            var array = new ushort [] { 123, 234 };

            using (var tensor = new TFTensor(array))
            {
                Assert.Equal(TFDataType.UInt16, tensor.TensorType);
                Assert.Equal(array.Rank, tensor.NumDims);
                Assert.Equal(array.Length, tensor.GetTensorDimension(0));
                Assert.Equal(new long [] { array.Length }, tensor.Shape);
                Assert.Equal((uint)sizeof(ushort) * array.Length, tensor.TensorByteSize.ToUInt32());
                Assert.Equal(array, tensor.GetValue());
            }
        }
Exemplo n.º 30
0
        public void ConstructDoubleArrayTensor()
        {
            var array = new [] { 123.456, 234.567 };

            using (var tensor = new TFTensor(array))
            {
                Assert.Equal(TFDataType.Double, tensor.TensorType);
                Assert.Equal(array.Rank, tensor.NumDims);
                Assert.Equal(array.Length, tensor.GetTensorDimension(0));
                Assert.Equal(new long [] { array.Length }, tensor.Shape);
                Assert.Equal((uint)sizeof(double) * array.Length, tensor.TensorByteSize.ToUInt32());
                Assert.Equal(array, tensor.GetValue());
            }
        }