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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 => 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. }
  39. }

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