forked from SciSharp/SciSharp-Stack-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelloWorld.cs
47 lines (40 loc) · 1.48 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
46
47
using System;
using System.Linq;
using Tensorflow.NumPy;
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;
}
}
}