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.

HelloWorld.cs 1.1 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Tensorflow;
  5. namespace TensorFlowNET.Examples
  6. {
  7. /// <summary>
  8. /// Simple hello world using TensorFlow
  9. /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py
  10. /// </summary>
  11. public class HelloWorld : Python, IExample
  12. {
  13. public bool Enabled => true;
  14. public bool Run()
  15. {
  16. /* Create a Constant op
  17. The op is added as a node to the default graph.
  18. The value returned by the constructor represents the output
  19. of the Constant op. */
  20. var str = "Hello, TensorFlow.NET!";
  21. var hello = tf.constant(str);
  22. // Start tf session
  23. return with(tf.Session(), sess =>
  24. {
  25. // Run the op
  26. var result = sess.run(hello);
  27. Console.WriteLine(result.ToString());
  28. return result.ToString().Equals(str);
  29. });
  30. }
  31. public void PrepareData()
  32. {
  33. }
  34. }
  35. }

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