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

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

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