Repository navigation
Expand file tree
/
Copy pathLayer.Apply.cs
More file actions
52 lines (43 loc) · 1.54 KB
/
Copy pathLayer.Apply.cs
File metadata and controls
52 lines (43 loc) · 1.54 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Threading;
using static Tensorflow.Binding;
namespace Tensorflow.Keras.Engine
{
public partial class Layer
{
/// <summary>
/// Wraps `call`, applying pre- and post-processing steps.
/// </summary>
/// <param name="input"></param>
/// <param name="state"></param>
/// <param name="training"></param>
/// <returns></returns>
public Tensors Apply(Tensors inputs, Tensor state = null, bool training = false)
{
callContext = callContext ?? new ThreadLocal<CallContext>()
{
Value = new CallContext()
};
if (_in_functional_construction_mode(inputs))
return FunctionalConstructionCall(inputs);
Tensors outputs = null;
var eager = tf.executing_eagerly();
using var ctxManager = CallContext.enter(build_graph: false);
string nameScope = "";
if (eager)
nameScope = Name;
else
nameScope = _name_scope();
tf_with(ops.name_scope(nameScope), scope =>
{
if (!built)
MaybeBuild(inputs);
outputs = Call(inputs, state: state, training: training);
// memory leak
// _set_connectivity_metadata_(inputs, outputs);
_handle_activity_regularization(inputs, outputs);
_set_mask_metadata(inputs, outputs, null);
});
return outputs;
}
}
}