Skip to content

Commit 67a58b3

Browse files
committed
change tensorflow to non-static class in order to execute some initialization.
1 parent fef7fe4 commit 67a58b3

File tree

106 files changed

+338
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+338
-250
lines changed

src/KerasNET.Core/Core.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Tensorflow;
2+
using static Tensorflow.Binding;
23

34
namespace Keras
45
{

src/KerasNET.Core/Layers/Dense.cs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ limitations under the License.
1919
using static Keras.Keras;
2020
using NumSharp;
2121
using Tensorflow.Operations.Activation;
22+
using static Tensorflow.Binding;
2223

2324
namespace Keras.Layers
2425
{

src/KerasNET.Core/Model.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ limitations under the License.
1919
using System;
2020
using System.Collections.Generic;
2121
using Tensorflow;
22-
using static Tensorflow.Python;
22+
using static Tensorflow.Binding;
2323

2424
namespace Keras
2525
{

src/TensorFlowNET.Core/APIs/tf.array.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
namespace Tensorflow
2222
{
23-
public static partial class tf
23+
public partial class tensorflow
2424
{
2525
/// <summary>
2626
/// Concatenates tensors along one dimension.
@@ -29,7 +29,7 @@ public static partial class tf
2929
/// <param name="axis"></param>
3030
/// <param name="name"></param>
3131
/// <returns>A `Tensor` resulting from concatenation of the input tensors.</returns>
32-
public static Tensor concat(IList<Tensor> values, int axis, string name = "concat")
32+
public Tensor concat(IList<Tensor> values, int axis, string name = "concat")
3333
{
3434
if (values.Count == 1)
3535
throw new NotImplementedException("tf.concat length is 1");
@@ -48,7 +48,7 @@ public static Tensor concat(IList<Tensor> values, int axis, string name = "conca
4848
/// A `Tensor` with the same data as `input`, but its shape has an additional
4949
/// dimension of size 1 added.
5050
/// </returns>
51-
public static Tensor expand_dims(Tensor input, int axis = -1, string name = null, int dim = -1)
51+
public Tensor expand_dims(Tensor input, int axis = -1, string name = null, int dim = -1)
5252
=> array_ops.expand_dims(input, axis, name, dim);
5353

5454
/// <summary>
@@ -58,14 +58,14 @@ public static Tensor expand_dims(Tensor input, int axis = -1, string name = null
5858
/// <param name="value"></param>
5959
/// <param name="name"></param>
6060
/// <returns></returns>
61-
public static Tensor fill<T>(Tensor dims, T value, string name = null)
61+
public Tensor fill<T>(Tensor dims, T value, string name = null)
6262
=> gen_array_ops.fill(dims, value, name: name);
6363

6464
/// <summary>
6565
/// Return the elements, either from `x` or `y`, depending on the `condition`.
6666
/// </summary>
6767
/// <returns></returns>
68-
public static Tensor where<Tx, Ty>(Tensor condition, Tx x, Ty y, string name = null)
68+
public Tensor where<Tx, Ty>(Tensor condition, Tx x, Ty y, string name = null)
6969
=> array_ops.where(condition, x, y, name);
7070

7171
/// <summary>
@@ -76,10 +76,10 @@ public static Tensor where<Tx, Ty>(Tensor condition, Tx x, Ty y, string name = n
7676
/// <param name="name"></param>
7777
/// <param name="conjugate"></param>
7878
/// <returns></returns>
79-
public static Tensor transpose<T1>(T1 a, int[] perm = null, string name = "transpose", bool conjugate = false)
79+
public Tensor transpose<T1>(T1 a, int[] perm = null, string name = "transpose", bool conjugate = false)
8080
=> array_ops.transpose(a, perm, name, conjugate);
8181

82-
public static Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1)
82+
public Tensor squeeze(Tensor input, int[] axis = null, string name = null, int squeeze_dims = -1)
8383
=> gen_array_ops.squeeze(input, axis, name);
8484

8585
/// <summary>
@@ -89,10 +89,10 @@ public static Tensor squeeze(Tensor input, int[] axis = null, string name = null
8989
/// <param name="axis"></param>
9090
/// <param name="name"></param>
9191
/// <returns></returns>
92-
public static Tensor stack(object values, int axis = 0, string name = "stack")
92+
public Tensor stack(object values, int axis = 0, string name = "stack")
9393
=> array_ops.stack(values, axis, name: name);
9494

95-
public static Tensor one_hot(Tensor indices, int depth,
95+
public Tensor one_hot(Tensor indices, int depth,
9696
Tensor on_value = null,
9797
Tensor off_value = null,
9898
TF_DataType dtype = TF_DataType.DtInvalid,
@@ -110,7 +110,7 @@ public static Tensor one_hot(Tensor indices, int depth,
110110
/// </param>
111111
/// <param name="name">A name for the operation (optional).</param>
112112
/// <returns>A `Tensor`. Has the same type as `input`.</returns>
113-
public static Tensor placeholder_with_default<T>(T input, int[] shape, string name = null)
113+
public Tensor placeholder_with_default<T>(T input, int[] shape, string name = null)
114114
=> gen_array_ops.placeholder_with_default(input, shape, name: name);
115115
}
116116
}

src/TensorFlowNET.Core/APIs/tf.control.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ limitations under the License.
1818

1919
namespace Tensorflow
2020
{
21-
public static partial class tf
21+
public partial class tensorflow
2222
{
23-
public static Tensor while_loop(Func<Tensor, Tensor> cond, Func<Tensor, Tensor> body, Tensor[] loop_vars,
23+
public Tensor while_loop(Func<Tensor, Tensor> cond, Func<Tensor, Tensor> body, Tensor[] loop_vars,
2424
TensorShape shape_invariants = null,
2525
int parallel_iterations = 10,
2626
bool back_prop = true,
@@ -37,7 +37,7 @@ public static Tensor while_loop(Func<Tensor, Tensor> cond, Func<Tensor, Tensor>
3737
maximum_iterations: maximum_iterations,
3838
return_same_structure: return_same_structure);
3939

40-
public static _ControlDependenciesController control_dependencies(Operation[] control_inputs)
40+
public _ControlDependenciesController control_dependencies(Operation[] control_inputs)
4141
=> ops.control_dependencies(control_inputs);
4242
}
4343
}

src/TensorFlowNET.Core/APIs/tf.distributions.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ limitations under the License.
1616

1717
namespace Tensorflow
1818
{
19-
public static partial class tf
19+
public partial class tensorflow
2020
{
21-
public static class distributions
21+
public distributions_internal distributions { get; } = new distributions_internal();
22+
23+
public class distributions_internal
2224
{
23-
public static Normal Normal(Tensor loc,
25+
public Normal Normal(Tensor loc,
2426
Tensor scale,
2527
bool validate_args = false,
2628
bool allow_nan_stats = true,

src/TensorFlowNET.Core/APIs/tf.exp.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ limitations under the License.
1616

1717
namespace Tensorflow
1818
{
19-
public static partial class tf
19+
public partial class tensorflow
2020
{
21-
public static Tensor exp(Tensor x,
21+
public Tensor exp(Tensor x,
2222
string name = null) => gen_math_ops.exp(x, name);
2323

2424
}

src/TensorFlowNET.Core/APIs/tf.gradients.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ limitations under the License.
1616

1717
namespace Tensorflow
1818
{
19-
public static partial class tf
19+
public partial class tensorflow
2020
{
21-
public static Tensor[] gradients(Tensor[] ys,
21+
public Tensor[] gradients(Tensor[] ys,
2222
Tensor[] xs,
2323
Tensor[] grad_ys = null,
2424
string name = "gradients",
@@ -36,7 +36,7 @@ public static Tensor[] gradients(Tensor[] ys,
3636
stop_gradients: stop_gradients);
3737
}
3838

39-
public static Tensor[] gradients(Tensor ys,
39+
public Tensor[] gradients(Tensor ys,
4040
Tensor[] xs,
4141
Tensor[] grad_ys = null,
4242
string name = "gradients",
@@ -54,7 +54,7 @@ public static Tensor[] gradients(Tensor ys,
5454
stop_gradients: stop_gradients);
5555
}
5656

57-
public static Tensor[] gradients(Tensor ys,
57+
public Tensor[] gradients(Tensor ys,
5858
Tensor xs,
5959
Tensor[] grad_ys = null,
6060
string name = "gradients",

src/TensorFlowNET.Core/APIs/tf.graph.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ limitations under the License.
1616

1717
namespace Tensorflow
1818
{
19-
public static partial class tf
19+
public partial class tensorflow
2020
{
21-
public static graph_util_impl graph_util => new graph_util_impl();
22-
public static Graph get_default_graph()
21+
public graph_util_impl graph_util => new graph_util_impl();
22+
public Graph get_default_graph()
2323
{
2424
return ops.get_default_graph();
2525
}
2626

27-
public static Graph Graph()
27+
public Graph Graph()
2828
=> new Graph();
2929
}
3030
}

src/TensorFlowNET.Core/APIs/tf.init.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ limitations under the License.
1818

1919
namespace Tensorflow
2020
{
21-
public static partial class tf
21+
public partial class tensorflow
2222
{
23-
public static IInitializer zeros_initializer => new Zeros();
24-
public static IInitializer ones_initializer => new Ones();
25-
public static IInitializer glorot_uniform_initializer => new GlorotUniform();
26-
public static IInitializer uniform_initializer => new RandomUniform();
23+
public IInitializer zeros_initializer => new Zeros();
24+
public IInitializer ones_initializer => new Ones();
25+
public IInitializer glorot_uniform_initializer => new GlorotUniform();
26+
public IInitializer uniform_initializer => new RandomUniform();
2727

28-
public static variable_scope variable_scope(string name,
28+
public variable_scope variable_scope(string name,
2929
string default_name = null,
3030
Tensor[] values = null,
3131
bool? reuse = null,
@@ -35,7 +35,7 @@ public static variable_scope variable_scope(string name,
3535
reuse: reuse,
3636
auxiliary_name_scope: auxiliary_name_scope);
3737

38-
public static variable_scope variable_scope(VariableScope scope,
38+
public variable_scope variable_scope(VariableScope scope,
3939
string default_name = null,
4040
Tensor[] values = null,
4141
bool? reuse = null,
@@ -45,7 +45,7 @@ public static variable_scope variable_scope(VariableScope scope,
4545
reuse: reuse,
4646
auxiliary_name_scope: auxiliary_name_scope);
4747

48-
public static IInitializer truncated_normal_initializer(float mean = 0.0f,
48+
public IInitializer truncated_normal_initializer(float mean = 0.0f,
4949
float stddev = 1.0f,
5050
int? seed = null,
5151
TF_DataType dtype = TF_DataType.DtInvalid) => new TruncatedNormal(mean: mean,

src/TensorFlowNET.Core/APIs/tf.io.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ limitations under the License.
1919

2020
namespace Tensorflow
2121
{
22-
public static partial class tf
22+
public partial class tensorflow
2323
{
24-
public static GFile gfile = new GFile();
25-
public static Tensor read_file(string filename, string name = null) => gen_io_ops.read_file(filename, name);
24+
public GFile gfile = new GFile();
25+
public Tensor read_file(string filename, string name = null) => gen_io_ops.read_file(filename, name);
2626

27-
public static gen_image_ops image => new gen_image_ops();
27+
public gen_image_ops image => new gen_image_ops();
2828

29-
public static void import_graph_def(GraphDef graph_def,
29+
public void import_graph_def(GraphDef graph_def,
3030
Dictionary<string, Tensor> input_map = null,
3131
string[] return_elements = null,
3232
string name = null,

src/TensorFlowNET.Core/APIs/tf.layers.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ limitations under the License.
1616

1717
using Tensorflow.Keras.Layers;
1818
using Tensorflow.Operations.Activation;
19+
using static Tensorflow.Binding;
1920

2021
namespace Tensorflow
2122
{
22-
public static partial class tf
23+
public partial class tensorflow
2324
{
24-
public static class layers
25+
public layers_internal layers { get; } = new layers_internal();
26+
27+
public class layers_internal
2528
{
26-
public static Tensor conv2d(Tensor inputs,
29+
public Tensor conv2d(Tensor inputs,
2730
int filters,
2831
int[] kernel_size,
2932
int[] strides = null,
@@ -80,7 +83,7 @@ public static Tensor conv2d(Tensor inputs,
8083
/// <param name="renorm"></param>
8184
/// <param name="renorm_momentum"></param>
8285
/// <returns></returns>
83-
public static Tensor batch_normalization(Tensor inputs,
86+
public Tensor batch_normalization(Tensor inputs,
8487
int axis = -1,
8588
float momentum = 0.99f,
8689
float epsilon = 0.001f,
@@ -124,7 +127,7 @@ public static Tensor batch_normalization(Tensor inputs,
124127
/// <param name="data_format"></param>
125128
/// <param name="name"></param>
126129
/// <returns></returns>
127-
public static Tensor max_pooling2d(Tensor inputs,
130+
public Tensor max_pooling2d(Tensor inputs,
128131
int[] pool_size,
129132
int[] strides,
130133
string padding = "valid",
@@ -140,7 +143,7 @@ public static Tensor max_pooling2d(Tensor inputs,
140143
return layer.apply(inputs);
141144
}
142145

143-
public static Tensor dense(Tensor inputs,
146+
public Tensor dense(Tensor inputs,
144147
int units,
145148
IActivation activation = null,
146149
bool use_bias = true,

src/TensorFlowNET.Core/APIs/tf.linalg.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ limitations under the License.
1616

1717
namespace Tensorflow
1818
{
19-
public static partial class tf
19+
public partial class tensorflow
2020
{
21-
public static Tensor diag(Tensor diagonal, string name = null)
21+
public Tensor diag(Tensor diagonal, string name = null)
2222
=> gen_array_ops.diag(diagonal, name: name);
2323

24-
public static Tensor matmul(Tensor a, Tensor b)
24+
public Tensor matmul(Tensor a, Tensor b)
2525
=> gen_math_ops.mat_mul(a, b);
2626

27-
public static Tensor batch_matmul(Tensor x, Tensor y)
27+
public Tensor batch_matmul(Tensor x, Tensor y)
2828
=> gen_math_ops.batch_mat_mul(x, y);
2929
}
3030
}

src/TensorFlowNET.Core/APIs/tf.loss.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ limitations under the License.
1616

1717
namespace Tensorflow
1818
{
19-
public static partial class tf
19+
public partial class tensorflow
2020
{
21-
public static LossesImpl losses => new LossesImpl();
21+
public LossesImpl losses => new LossesImpl();
2222
}
2323
}

0 commit comments

Comments
 (0)