forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicEagerApi.cs
More file actions
38 lines (34 loc) · 1.14 KB
/
BasicEagerApi.cs
File metadata and controls
38 lines (34 loc) · 1.14 KB
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
using System;
using System.Collections.Generic;
using System.Text;
using Tensorflow;
namespace TensorFlowNET.Examples
{
/// <summary>
/// Basic introduction to TensorFlow's Eager API.
/// https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/basic_eager_api.py
/// </summary>
public class BasicEagerApi : IExample
{
private Tensor a, b, c, d;
public void Run()
{
// Set Eager API
Console.WriteLine("Setting Eager mode...");
tf.enable_eager_execution();
// Define constant tensors
Console.WriteLine("Define constant tensors");
a = tf.constant(2);
Console.WriteLine($"a = {a}");
b = tf.constant(3);
Console.WriteLine($"b = {b}");
// Run the operation without the need for tf.Session
Console.WriteLine("Running operations, without tf.Session");
c = a + b;
Console.WriteLine($"a + b = {c}");
d = a * b;
Console.WriteLine($"a * b = {d}");
// Full compatibility with Numpy
}
}
}