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.

BasicEagerApi.cs 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using Tensorflow;
  3. using static Tensorflow.Binding;
  4. namespace TensorFlowNET.Examples
  5. {
  6. /// <summary>
  7. /// Basic introduction to TensorFlow's Eager API.
  8. /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/basic_eager_api.py
  9. /// </summary>
  10. public class BasicEagerApi : IExample
  11. {
  12. public bool Enabled { get; set; } = false;
  13. public string Name => "Basic Eager";
  14. public bool IsImportingGraph { get; set; } = false;
  15. private Tensor a, b, c, d;
  16. public bool Run()
  17. {
  18. // Set Eager API
  19. Console.WriteLine("Setting Eager mode...");
  20. tf.enable_eager_execution();
  21. // Define constant tensors
  22. Console.WriteLine("Define constant tensors");
  23. a = tf.constant(2);
  24. Console.WriteLine($"a = {a}");
  25. b = tf.constant(3);
  26. Console.WriteLine($"b = {b}");
  27. // Run the operation without the need for tf.Session
  28. Console.WriteLine("Running operations, without tf.Session");
  29. c = a + b;
  30. Console.WriteLine($"a + b = {c}");
  31. d = a * b;
  32. Console.WriteLine($"a * b = {d}");
  33. // Full compatibility with Numpy
  34. return true;
  35. }
  36. public void PrepareData()
  37. {
  38. }
  39. public Graph ImportGraph()
  40. {
  41. throw new NotImplementedException();
  42. }
  43. public Graph BuildGraph()
  44. {
  45. throw new NotImplementedException();
  46. }
  47. public void Predict(Session sess)
  48. {
  49. throw new NotImplementedException();
  50. }
  51. public void Train(Session sess)
  52. {
  53. throw new NotImplementedException();
  54. }
  55. public void Test(Session sess)
  56. {
  57. throw new NotImplementedException();
  58. }
  59. }
  60. }