-
Notifications
You must be signed in to change notification settings - Fork 103
/
HelloWorld.cs
45 lines (37 loc) · 1.32 KB
/
HelloWorld.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Linq;
using static Tensorflow.Binding;
namespace TensorFlowNET.Examples;
/// <summary>
/// A very simple "hello world" using TensorFlow v2 tensors.
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/tensorflow_v2/notebooks/1_Introduction/helloworld.ipynb
/// </summary>
public class HelloWorld : SciSharpExample, IExample
{
public ExampleConfig InitConfig()
=> Config = new ExampleConfig
{
Name = "Hello World"
};
public HelloWorld()
{
str = string.Join("", Enumerable.Range(0, 1024 * 1024 * 20).Select(x => "X"));
}
public static string str;
public bool Run()
{
// Eager model is enabled by default.
tf.enable_eager_execution();
/* Create a Constant op
The op is added as a node to the default graph.
The value returned by the constructor represents the output
of the Constant op. */
// var str = string.Join("", Enumerable.Range(0, 1024 * 1024 * 20).Select(x => "X"));
using var hello = tf.constant(str);
// tf.Tensor: shape=(), dtype=string, numpy=b'Hello, TensorFlow.NET!'
// print(hello);
var tensor = hello.StringData();
//return tensor.ToString() == $"'{str}'";
return true;
}
}