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.

VariableTest.cs 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Tensorflow;
  6. namespace TensorFlowNET.UnitTest
  7. {
  8. [TestClass]
  9. public class VariableTest : Python
  10. {
  11. [TestMethod]
  12. public void StringVar()
  13. {
  14. var mammal1 = tf.Variable("Elephant", "var1", tf.chars);
  15. var mammal2 = tf.Variable("Tiger");
  16. }
  17. [TestMethod]
  18. public void ScalarVar()
  19. {
  20. var x = tf.Variable(3);
  21. var y = tf.Variable(6f);
  22. }
  23. /// <summary>
  24. /// https://databricks.com/tensorflow/variables
  25. /// </summary>
  26. [TestMethod]
  27. public void Add()
  28. {
  29. var x = tf.Variable(0, name: "x");
  30. var model = tf.global_variables_initializer();
  31. using (var session = tf.Session())
  32. {
  33. session.run(model);
  34. for(int i = 0; i < 5; i++)
  35. {
  36. var x1 = x + 1;
  37. var result = session.run(x1);
  38. print(result);
  39. }
  40. }
  41. }
  42. }
  43. }

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