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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 int Priority => 100;
  14. public bool Enabled => false;
  15. public string Name => "Basic Eager";
  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. }
  41. }

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