forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayer.Apply.cs
More file actions
62 lines (51 loc) · 1.91 KB
/
Layer.Apply.cs
File metadata and controls
62 lines (51 loc) · 1.91 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
53
54
55
56
57
58
59
60
61
62
using System.Threading;
using Tensorflow.Common.Types;
using static Tensorflow.Binding;
namespace Tensorflow.Keras.Engine
{
public partial class Layer
{
/// <summary>
/// Wraps `call`, applying pre- and post-processing steps.
/// </summary>
/// <param name="inputs"></param>
/// <param name="states"></param>
/// <param name="training"></param>
/// <returns></returns>
public virtual Tensors Apply(Tensors inputs, Tensors states = null, bool? training = false, IOptionalArgs? optional_args = null)
{
if (callContext.Value == null)
callContext.Value = new CallContext();
if (_in_functional_construction_mode(inputs))
return FunctionalConstructionCall(inputs);
var eager = tf.executing_eagerly();
using var ctxManager = CallContext.enter(build_graph: false);
string nameScope = eager ? name : _name_scope();
var scope = ops.name_scope(nameScope);
scope.__enter__();
if (!built)
MaybeBuild(inputs);
var outputs = Call(inputs, state: states, training: training);
// memory leak
// _set_connectivity_metadata_(inputs, outputs);
_handle_activity_regularization(inputs, outputs);
_set_mask_metadata(inputs, outputs, null);
// TODO(Rinne): set save spec if null
scope.__exit__();
return outputs;
}
// TODO(Rinne): remove it and completely fix issue 1084
[Obsolete]
private bool _enforce_layer_construction = false;
[Obsolete]
internal void enforce_layer_construction()
{
_enforce_layer_construction = true;
}
[Obsolete]
internal void unset_layer_construction()
{
_enforce_layer_construction = false;
}
}
}