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.8 kB

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