FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/src/TensorFlowNET.Core/APIs/tf.nn.cs at master · Oceania2018/TensorFlow.NET · GitHub
Oceania2018
/
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.Core
/
APIs
/
tf.nn.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
211 lines (179 loc) · 9.58 KB
Breadcrumbs
TensorFlow.NET
/
src
/
TensorFlowNET.Core
/
APIs
/
tf.nn.cs
Copy path
File metadata and controls
211 lines (179 loc) · 9.58 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*****************************************************************************
Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
******************************************************************************/
using
Tensorflow
.
Operations
;
using
Tensorflow
.
Operations
.
Activation
;
using
static
Tensorflow
.
Binding
;
namespace
Tensorflow
{
public
partial
class
tensorflow
{
public
nn_internal
nn
{
get
;
}
=
new
nn_internal
(
)
;
public
class
nn_internal
{
public
Tensor
conv2d
(
Tensor
input
,
RefVariable
filter
,
int
[
]
strides
,
string
padding
,
bool
use_cudnn_on_gpu
=
true
,
string
data_format
=
"NHWC"
,
int
[
]
dilations
=
null
,
string
name
=
null
)
{
var
parameters
=
new
Conv2dParams
{
Input
=
input
,
Filter
=
filter
,
Strides
=
strides
,
Padding
=
padding
,
UseCudnnOnGpu
=
use_cudnn_on_gpu
,
DataFormat
=
data_format
,
Name
=
name
}
;
if
(
dilations
!=
null
)
parameters
.
Dilations
=
dilations
;
return
gen_nn_ops
.
conv2d
(
parameters
)
;
}
/// <summary>
/// Computes dropout.
/// </summary>
/// <param name="x">A floating point tensor.</param>
/// <param name="keep_prob">(deprecated) A deprecated alias for `(1-rate)`.</param>
/// <param name="noise_shape"></param>
/// <param name="seed">Used to create random seeds.</param>
/// <param name="name"></param>
/// <param name="rate">A scalar `Tensor` with the same type as `x`.</param>
/// <returns>A Tensor of the same shape of `x`.</returns>
public
Tensor
dropout
(
Tensor
x
,
Tensor
keep_prob
=
null
,
Tensor
noise_shape
=
null
,
int
?
seed
=
null
,
string
name
=
null
,
float
?
rate
=
null
)
{
Tensor
keep
=
null
;
if
(
keep_prob
!=
null
)
keep
=
1.0f
-
keep_prob
;
var
rate_tensor
=
keep
;
return
nn_ops
.
dropout_v2
(
x
,
rate
:
rate_tensor
,
noise_shape
:
noise_shape
,
seed
:
seed
,
name
:
name
)
;
}
/// <summary>
/// Creates a recurrent neural network specified by RNNCell `cell`.
/// </summary>
/// <param name="cell">An instance of RNNCell.</param>
/// <param name="inputs">The RNN inputs.</param>
/// <param name="dtype"></param>
/// <param name="swap_memory"></param>
/// <param name="time_major"></param>
/// <returns>A pair (outputs, state)</returns>
public
(
Tensor
,
Tensor
)
dynamic_rnn
(
RNNCell
cell
,
Tensor
inputs
,
Tensor
sequence_length
=
null
,
TF_DataType
dtype
=
TF_DataType
.
DtInvalid
,
int
?
parallel_iterations
=
null
,
bool
swap_memory
=
false
,
bool
time_major
=
false
)
=>
rnn
.
dynamic_rnn
(
cell
,
inputs
,
sequence_length
:
sequence_length
,
dtype
:
dtype
,
parallel_iterations
:
parallel_iterations
,
swap_memory
:
swap_memory
,
time_major
:
time_major
)
;
public
Tensor
elu
(
Tensor
features
,
string
name
=
null
)
=>
gen_nn_ops
.
elu
(
features
,
name
:
name
)
;
public
(
Tensor
,
Tensor
)
moments
(
Tensor
x
,
int
[
]
axes
,
string
name
=
null
,
bool
keep_dims
=
false
)
=>
nn_impl
.
moments
(
x
,
axes
,
name
:
name
,
keep_dims
:
keep_dims
)
;
public
Tensor
embedding_lookup
(
RefVariable
@params
,
Tensor
ids
,
string
partition_strategy
=
"mod"
,
string
name
=
null
)
=>
embedding_ops
.
_embedding_lookup_and_transform
(
@params
,
ids
,
partition_strategy
:
partition_strategy
,
name
:
name
)
;
public
Tensor
embedding_lookup
(
Tensor
@params
,
Tensor
ids
,
string
partition_strategy
=
"mod"
,
string
name
=
null
)
=>
embedding_ops
.
_embedding_lookup_and_transform
(
new
Tensor
[
]
{
@params
}
,
ids
,
partition_strategy
:
partition_strategy
,
name
:
name
)
;
public
IActivation
relu
(
)
=>
new
relu
(
)
;
public
Tensor
relu
(
Tensor
features
,
string
name
=
null
)
=>
gen_nn_ops
.
relu
(
features
,
name
)
;
public
Tensor
[
]
fused_batch_norm
(
Tensor
x
,
RefVariable
scale
,
RefVariable
offset
,
Tensor
mean
=
null
,
Tensor
variance
=
null
,
float
epsilon
=
0.001f
,
string
data_format
=
"NHWC"
,
bool
is_training
=
true
,
string
name
=
null
)
=>
nn_impl
.
fused_batch_norm
(
x
,
scale
,
offset
,
mean
,
variance
,
epsilon
:
epsilon
,
data_format
:
data_format
,
is_training
:
is_training
,
name
:
name
)
;
public
IPoolFunction
max_pool_fn
=>
new
MaxPoolFunction
(
)
;
public
Tensor
max_pool
(
Tensor
value
,
int
[
]
ksize
,
int
[
]
strides
,
string
padding
,
string
data_format
=
"NHWC"
,
string
name
=
null
)
=>
nn_ops
.
max_pool
(
value
,
ksize
,
strides
,
padding
,
data_format
:
data_format
,
name
:
name
)
;
public
Tensor
in_top_k
(
Tensor
predictions
,
Tensor
targets
,
int
k
,
string
name
=
"InTopK"
)
=>
gen_ops
.
in_top_k
(
predictions
,
targets
,
k
,
name
)
;
public
Tensor
[
]
top_k
(
Tensor
input
,
int
k
=
1
,
bool
sorted
=
true
,
string
name
=
null
)
=>
gen_nn_ops
.
top_kv2
(
input
,
k
:
k
,
sorted
:
sorted
,
name
:
name
)
;
public
Tensor
bias_add
(
Tensor
value
,
RefVariable
bias
,
string
data_format
=
null
,
string
name
=
null
)
{
return
tf_with
(
ops
.
name_scope
(
name
,
"BiasAdd"
,
new
{
value
,
bias
}
)
,
scope
=>
{
name
=
scope
;
return
gen_nn_ops
.
bias_add
(
value
,
bias
,
data_format
:
data_format
,
name
:
name
)
;
}
)
;
}
/// <summary>
/// Local Response Normalization.
/// </summary>
/// <param name="input"></param>
/// <param name="depth_radius"></param>
/// <param name="bias"></param>
/// <param name="alpha"></param>
/// <param name="beta"></param>
/// <param name="name"></param>
/// <returns></returns>
public
Tensor
lrn
(
Tensor
input
,
int
depth_radius
=
5
,
int
bias
=
1
,
int
alpha
=
1
,
float
beta
=
0.5f
,
string
name
=
null
)
=>
gen_nn_ops
.
local_response_normalization
(
input
,
depth_radius
:
depth_radius
,
bias
:
bias
,
alpha
:
alpha
,
beta
:
beta
,
name
:
name
)
;
public
Tensor
leaky_relu
(
Tensor
features
,
float
alpha
=
0.2f
,
string
name
=
null
)
=>
nn_ops
.
leaky_relu
(
features
,
alpha
:
alpha
,
name
:
name
)
;
public
rnn_cell_impl
rnn_cell
=>
new
rnn_cell_impl
(
)
;
public
Tensor
sigmoid_cross_entropy_with_logits
(
Tensor
labels
,
Tensor
logits
,
string
name
=
null
)
=>
nn_impl
.
sigmoid_cross_entropy_with_logits
(
labels
:
labels
,
logits
:
logits
,
name
:
name
)
;
public
Tensor
softmax
(
Tensor
logits
,
int
axis
=
-
1
,
string
name
=
null
)
=>
gen_nn_ops
.
softmax
(
logits
,
name
)
;
/// <summary>
/// Computes sparse softmax cross entropy between `logits` and `labels`.
/// </summary>
/// <param name="labels"></param>
/// <param name="logits"></param>
/// <param name="name"></param>
/// <returns></returns>
public
Tensor
sparse_softmax_cross_entropy_with_logits
(
Tensor
labels
=
null
,
Tensor
logits
=
null
,
string
name
=
null
)
=>
nn_ops
.
sparse_softmax_cross_entropy_with_logits
(
labels
:
labels
,
logits
:
logits
,
name
:
name
)
;
/// <summary>
/// Computes softmax cross entropy between `logits` and `labels`.
/// </summary>
/// <param name="labels"></param>
/// <param name="logits"></param>
/// <param name="dim"></param>
/// <param name="name"></param>
/// <returns></returns>
public
Tensor
softmax_cross_entropy_with_logits
(
Tensor
labels
,
Tensor
logits
,
int
dim
=
-
1
,
string
name
=
null
)
{
tf_with
(
ops
.
name_scope
(
name
,
"softmax_cross_entropy_with_logits_sg"
,
new
{
logits
,
labels
}
)
,
scope
=>
{
name
=
scope
;
labels
=
array_ops
.
stop_gradient
(
labels
,
name
:
"labels_stop_gradient"
)
;
}
)
;
return
softmax_cross_entropy_with_logits_v2
(
labels
,
logits
,
axis
:
dim
,
name
:
name
)
;
}
public
Tensor
softmax_cross_entropy_with_logits_v2
(
Tensor
labels
,
Tensor
logits
,
int
axis
=
-
1
,
string
name
=
null
)
=>
nn_ops
.
softmax_cross_entropy_with_logits_v2_helper
(
labels
,
logits
,
axis
:
axis
,
name
:
name
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL