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
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 int Priority => 1;
  14. public bool Enabled { get; set; } = true;
  15. public string Name => "Hello World";
  16. public bool ImportGraph { get; set; } = false;
  17. public bool Run()
  18. {
  19. /* Create a Constant op
  20. The op is added as a node to the default graph.
  21. The value returned by the constructor represents the output
  22. of the Constant op. */
  23. var str = "Hello, TensorFlow.NET!";
  24. var hello = tf.constant(str);
  25. // Start tf session
  26. return with(tf.Session(), sess =>
  27. {
  28. // Run the op
  29. var result = sess.run(hello);
  30. Console.WriteLine(result.ToString());
  31. return result.ToString().Equals(str);
  32. });
  33. }
  34. public void PrepareData()
  35. {
  36. }
  37. }
  38. }

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