You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConstantTest.cs 1.3 kB

6 years ago
6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using NumSharp.Core;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using Tensorflow;
  8. namespace TensorFlowNET.UnitTest
  9. {
  10. [TestClass]
  11. public class ConstantTest
  12. {
  13. Tensor tensor;
  14. [TestMethod]
  15. public void ScalarConst()
  16. {
  17. tensor = tf.constant(8); // int
  18. tensor = tf.constant(6.0f); // float
  19. tensor = tf.constant(6.0); // double
  20. }
  21. [TestMethod]
  22. public void StringConst()
  23. {
  24. tensor = tf.constant("Elephant");
  25. }
  26. [TestMethod]
  27. public void ZerosConst()
  28. {
  29. tensor = tf.zeros(new Shape(3, 2), TF_DataType.TF_INT32, "x");
  30. Assert.AreEqual(tensor.shape[0], 3);
  31. Assert.AreEqual(tensor.shape[0], 2);
  32. Assert.IsTrue(Enumerable.SequenceEqual(new int[] { 0, 0, 0, 0, 0, 0 }, tensor.Data<int>()));
  33. tensor = tf.zeros(new Shape(200, 300), TF_DataType.TF_INT32, "x");
  34. }
  35. [TestMethod]
  36. public void NDimConst()
  37. {
  38. var nd = np.array(new int[][]
  39. {
  40. new int[]{ 1, 2, 3 },
  41. new int[]{ 4, 5, 6 }
  42. });
  43. tensor = tf.constant(nd);
  44. }
  45. }
  46. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。