FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/src/TensorFlowNET.Console/MemoryBasicTest.cs at master · feliwir/TensorFlow.NET · GitHub
feliwir
/
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
/
src
/
TensorFlowNET.Console
/
MemoryBasicTest.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
176 lines (158 loc) · 6.01 KB
Breadcrumbs
TensorFlow.NET
/
src
/
TensorFlowNET.Console
/
MemoryBasicTest.cs
Copy path
File metadata and controls
176 lines (158 loc) · 6.01 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using
Tensorflow
.
NumPy
;
using
System
;
using
Tensorflow
.
Keras
.
ArgsDefinition
;
using
Tensorflow
.
Keras
.
Engine
.
DataAdapters
;
using
static
Tensorflow
.
Binding
;
using
static
Tensorflow
.
KerasApi
;
using
System
.
Linq
;
using
System
.
Collections
.
Generic
;
namespace
Tensorflow
{
class
MemoryBasicTest
{
public
Action
<
int
,
int
>
Placeholder
=>
(
epoch
,
iterate
)
=>
{
var
ph
=
array_ops
.
placeholder
(
tf
.
float32
,
(
10
,
512
,
512
,
3
)
)
;
}
;
/// <summary>
///
/// </summary>
public
Action
<
int
,
int
>
Constant
=>
(
epoch
,
iterate
)
=>
{
var
tensor
=
tf
.
constant
(
3112.0f
)
;
}
;
public
Action
<
int
,
int
>
Constant2x3
=>
(
epoch
,
iterate
)
=>
{
var
nd
=
np
.
arange
(
1000
)
.
reshape
(
(
10
,
100
)
)
;
var
tensor
=
tf
.
constant
(
nd
)
;
var
data
=
tensor
.
numpy
(
)
;
}
;
public
Action
<
int
,
int
>
ConstantString
=>
(
epoch
,
iterate
)
=>
{
var
strList
=
new
string
[
]
{
"Biden immigration bill would put millions of illegal immigrants on 8-year fast-track to citizenship"
,
"The Associated Press, which also reported that the eight-year path is in the bill."
,
"The bill would also include provisions to stem the flow of migration by addressing root causes of migration from south of the border."
}
;
var
tensor
=
tf
.
constant
(
strList
,
TF_DataType
.
TF_STRING
)
;
var
data
=
tensor
.
StringData
(
)
;
}
;
public
Action
<
int
,
int
>
Variable
=>
(
epoch
,
iterate
)
=>
{
var
nd
=
np
.
arange
(
1
*
256
*
256
*
3
)
.
reshape
(
(
1
,
256
,
256
,
3
)
)
;
ResourceVariable
variable
=
tf
.
Variable
(
nd
)
;
}
;
public
Action
<
int
,
int
>
VariableRead
=>
(
epoch
,
iterate
)
=>
{
var
nd
=
np
.
zeros
(
1
*
256
*
256
*
3
)
.
astype
(
np
.
float32
)
.
reshape
(
(
1
,
256
,
256
,
3
)
)
;
ResourceVariable
variable
=
tf
.
Variable
(
nd
)
;
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
var
v
=
variable
.
numpy
(
)
;
}
}
;
public
Action
<
int
,
int
>
VariableAssign
=>
(
epoch
,
iterate
)
=>
{
ResourceVariable
variable
=
tf
.
Variable
(
3112f
)
;
AssignVariable
(
variable
)
;
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
var
v
=
variable
.
numpy
(
)
;
if
(
(
float
)
v
!=
1984f
)
throw
new
ValueError
(
""
)
;
}
}
;
void
AssignVariable
(
IVariableV1
v
)
{
using
var
tensor
=
tf
.
constant
(
1984f
)
;
v
.
assign
(
tensor
)
;
}
public
Action
<
int
,
int
>
MathAdd
=>
(
epoch
,
iterate
)
=>
{
var
x
=
tf
.
constant
(
3112.0f
)
;
var
y
=
tf
.
constant
(
3112.0f
)
;
var
z
=
x
+
y
;
}
;
public
Action
<
int
,
int
>
Gradient
=>
(
epoch
,
iterate
)
=>
{
var
w
=
tf
.
constant
(
3112.0f
)
;
using
var
tape
=
tf
.
GradientTape
(
)
;
tape
.
watch
(
w
)
;
var
loss
=
w
*
w
;
var
grad
=
tape
.
gradient
(
loss
,
w
)
;
}
;
public
Action
<
int
,
int
>
Conv2DWithTensor
=>
(
epoch
,
iterate
)
=>
{
var
input
=
array_ops
.
zeros
(
(
10
,
32
,
32
,
3
)
,
dtypes
.
float32
)
;
var
filter
=
array_ops
.
zeros
(
(
3
,
3
,
3
,
32
)
,
dtypes
.
float32
)
;
var
strides
=
new
[
]
{
1
,
1
,
1
,
1
}
;
var
dilations
=
new
[
]
{
1
,
1
,
1
,
1
}
;
var
results
=
tf
.
Runner
.
TFE_FastPathExecute
(
new
FastPathOpExecInfo
(
"Conv2D"
,
null
,
input
,
filter
)
{
attrs
=
ConvertToDict
(
new
{
strides
,
use_cudnn_on_gpu
=
true
,
padding
=
"VALID"
,
explicit_paddings
=
new
int
[
0
]
,
data_format
=
"NHWC"
,
dilations
}
)
}
)
;
}
;
public
Action
<
int
,
int
>
Conv2DWithVariable
=>
(
epoch
,
iterate
)
=>
{
var
input
=
array_ops
.
zeros
(
(
10
,
32
,
32
,
3
)
,
dtypes
.
float32
)
;
var
filter
=
tf
.
Variable
(
array_ops
.
zeros
(
(
3
,
3
,
3
,
32
)
,
dtypes
.
float32
)
)
;
var
strides
=
new
[
]
{
1
,
1
,
1
,
1
}
;
var
dilations
=
new
[
]
{
1
,
1
,
1
,
1
}
;
var
results
=
tf
.
Runner
.
TFE_FastPathExecute
(
new
FastPathOpExecInfo
(
"Conv2D"
,
null
,
input
,
filter
)
{
attrs
=
ConvertToDict
(
new
{
strides
,
use_cudnn_on_gpu
=
true
,
padding
=
"VALID"
,
explicit_paddings
=
new
int
[
0
]
,
data_format
=
"NHWC"
,
dilations
}
)
}
)
;
}
;
public
Action
<
int
,
int
>
Dataset
=>
(
epoch
,
iterate
)
=>
{
Shape
shape
=
(
16
,
32
,
32
,
3
)
;
var
images
=
np
.
arange
(
shape
.
size
)
.
astype
(
np
.
float32
)
.
reshape
(
shape
.
dims
)
;
var
data_handler
=
new
DataHandler
(
new
DataHandlerArgs
{
X
=
images
,
BatchSize
=
2
,
StepsPerEpoch
=
-
1
,
InitialEpoch
=
0
,
Epochs
=
2
,
MaxQueueSize
=
10
,
Workers
=
1
,
UseMultiprocessing
=
false
,
StepsPerExecution
=
tf
.
Variable
(
1
)
}
)
;
/*foreach (var (_epoch, iterator) in data_handler.enumerate_epochs())
{
foreach (var step in data_handler.steps())
iterator.next();
}*/
}
;
}
}
Back
|
FazBrowse Home
|
New Git URL