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.8 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using Tensorflow;
  3. using static Tensorflow.Python;
  4. namespace TensorFlowNET.Examples
  5. {
  6. /// <summary>
  7. /// Simple hello world using TensorFlow
  8. /// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py
  9. /// </summary>
  10. public class HelloWorld : IExample
  11. {
  12. public bool Enabled { get; set; } = true;
  13. public string Name => "Hello World";
  14. public bool IsImportingGraph { get; set; } = false;
  15. public bool Run()
  16. {
  17. /* Create a Constant op
  18. The op is added as a node to the default graph.
  19. The value returned by the constructor represents the output
  20. of the Constant op. */
  21. var str = "Hello, TensorFlow.NET!";
  22. var hello = tf.constant(str);
  23. // Start tf session
  24. return with(tf.Session(), sess =>
  25. {
  26. // Run the op
  27. var result = sess.run(hello);
  28. string result_string = string.Join("", result.GetData<char>());
  29. Console.WriteLine(result_string);
  30. return result_string.Equals(str);
  31. });
  32. }
  33. public void PrepareData()
  34. {
  35. }
  36. public Graph ImportGraph()
  37. {
  38. throw new NotImplementedException();
  39. }
  40. public Graph BuildGraph()
  41. {
  42. throw new NotImplementedException();
  43. }
  44. public void Train(Session sess)
  45. {
  46. throw new NotImplementedException();
  47. }
  48. public void Predict(Session sess)
  49. {
  50. throw new NotImplementedException();
  51. }
  52. public void Test(Session sess)
  53. {
  54. throw new NotImplementedException();
  55. }
  56. }
  57. }