FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/test/TensorFlowNET.Examples/Keras.cs at master · dot-nethub/TensorFlow.NET · GitHub
dot-nethub
/
TensorFlow.NET
Public
forked from
SciSharp/TensorFlow.NET
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TensorFlow.NET
/
test
/
TensorFlowNET.Examples
/
Keras.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
98 lines (80 loc) · 2.57 KB
Breadcrumbs
TensorFlow.NET
/
test
/
TensorFlowNET.Examples
/
Keras.cs
Copy path
File metadata and controls
98 lines (80 loc) · 2.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using
System
;
using
System
.
Collections
.
Generic
;
using
Tensorflow
;
using
Keras
.
Layers
;
using
NumSharp
;
using
Keras
;
namespace
TensorFlowNET
.
Examples
{
public
class
Keras
:
IExample
{
public
bool
Enabled
{
get
;
set
;
}
=
true
;
public
bool
IsImportingGraph
{
get
;
set
;
}
=
false
;
public
string
Name
=>
"Keras"
;
public
bool
Run
(
)
{
Console
.
WriteLine
(
"================================== Keras =================================="
)
;
#region data
var
batch_size
=
1000
;
var
(
X
,
Y
)
=
XOR
(
batch_size
)
;
//var (X, Y, batch_size) = (np.array(new float[,]{{1, 0 },{1, 1 },{0, 0 },{0, 1 }}), np.array(new int[] { 0, 1, 1, 0 }), 4);
#endregion
#region features
var
(
features
,
labels
)
=
(
new
Tensor
(
X
)
,
new
Tensor
(
Y
)
)
;
var
num_steps
=
10000
;
#endregion
#region model
var
m
=
new
Model
(
)
;
//m.Add(new Dense(8, name: "Hidden", activation: tf.nn.relu())).Add(new Dense(1, name:"Output"));
m
.
Add
(
new
ILayer
[
]
{
new
Dense
(
8
,
name
:
"Hidden_1"
,
activation
:
tf
.
nn
.
relu
(
)
)
,
new
Dense
(
1
,
name
:
"Output"
)
}
)
;
m
.
train
(
num_steps
,
(
X
,
Y
)
)
;
#endregion
return
true
;
}
static
(
NDArray
,
NDArray
)
XOR
(
int
samples
)
{
var
X
=
new
List
<
float
[
]
>
(
)
;
var
Y
=
new
List
<
float
>
(
)
;
var
r
=
new
Random
(
)
;
for
(
int
i
=
0
;
i
<
samples
;
i
++
)
{
var
x1
=
(
float
)
r
.
Next
(
0
,
2
)
;
var
x2
=
(
float
)
r
.
Next
(
0
,
2
)
;
var
y
=
0.0f
;
if
(
x1
==
x2
)
y
=
1.0f
;
X
.
Add
(
new
float
[
]
{
x1
,
x2
}
)
;
Y
.
Add
(
y
)
;
}
return
(
np
.
array
(
X
.
ToArray
(
)
)
,
np
.
array
(
Y
.
ToArray
(
)
)
)
;
}
public
Graph
BuildGraph
(
)
{
throw
new
NotImplementedException
(
)
;
}
public
Graph
ImportGraph
(
)
{
throw
new
NotImplementedException
(
)
;
}
public
void
Predict
(
Session
sess
)
{
throw
new
NotImplementedException
(
)
;
}
public
void
PrepareData
(
)
{
throw
new
NotImplementedException
(
)
;
}
public
void
Test
(
Session
sess
)
{
throw
new
NotImplementedException
(
)
;
}
public
void
Train
(
Session
sess
)
{
throw
new
NotImplementedException
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL