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

1234567891011121314151617181920212223242526272829303132333435363738
  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. private Tensor a, b, c, d;
  14. public void Run()
  15. {
  16. // Set Eager API
  17. Console.WriteLine("Setting Eager mode...");
  18. tf.enable_eager_execution();
  19. // Define constant tensors
  20. Console.WriteLine("Define constant tensors");
  21. a = tf.constant(2);
  22. Console.WriteLine($"a = {a}");
  23. b = tf.constant(3);
  24. Console.WriteLine($"b = {b}");
  25. // Run the operation without the need for tf.Session
  26. Console.WriteLine("Running operations, without tf.Session");
  27. c = a + b;
  28. Console.WriteLine($"a + b = {c}");
  29. d = a * b;
  30. Console.WriteLine($"a * b = {d}");
  31. // Full compatibility with Numpy
  32. }
  33. }
  34. }

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