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

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