| @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Examples", "t | |||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\TensorFlowNET.Core\TensorFlowNET.Core.csproj", "{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\TensorFlowNET.Core\TensorFlowNET.Core.csproj", "{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}" | ||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization", "TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}" | |||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Visualization", "src\TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{0254BFF9-453C-4FE0-9609-3644559A79CE}" | |||||
| EndProject | EndProject | ||||
| Global | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| @@ -29,10 +29,10 @@ Global | |||||
| {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|Any CPU.Build.0 = Debug|Any CPU | {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.ActiveCfg = Release|Any CPU | {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.Build.0 = Release|Any CPU | {FD682AC0-7B2D-45D3-8B0D-C6D678B04144}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| {0254BFF9-453C-4FE0-9609-3644559A79CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {0254BFF9-453C-4FE0-9609-3644559A79CE}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {0254BFF9-453C-4FE0-9609-3644559A79CE}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {0254BFF9-453C-4FE0-9609-3644559A79CE}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
| @@ -19,14 +19,30 @@ namespace Tensorflow | |||||
| int[] dilation_rate = null, | int[] dilation_rate = null, | ||||
| bool use_bias = true, | bool use_bias = true, | ||||
| IActivation activation = null, | IActivation activation = null, | ||||
| IInitializer kernel_initializer = null) | |||||
| IInitializer kernel_initializer = null, | |||||
| IInitializer bias_initializer = null, | |||||
| bool trainable = true, | |||||
| string name = null) | |||||
| { | { | ||||
| if (strides == null) | if (strides == null) | ||||
| strides = new int[] { 1, 1 }; | strides = new int[] { 1, 1 }; | ||||
| if (dilation_rate == null) | if (dilation_rate == null) | ||||
| dilation_rate = new int[] { 1, 1 }; | dilation_rate = new int[] { 1, 1 }; | ||||
| if (bias_initializer == null) | |||||
| bias_initializer = tf.zeros_initializer; | |||||
| var layer = new Conv2D(filters, kernel_size); | |||||
| var layer = new Conv2D(filters, | |||||
| kernel_size: kernel_size, | |||||
| strides: strides, | |||||
| padding: padding, | |||||
| data_format: data_format, | |||||
| dilation_rate: dilation_rate, | |||||
| activation: activation, | |||||
| use_bias: use_bias, | |||||
| kernel_initializer: kernel_initializer, | |||||
| bias_initializer: bias_initializer, | |||||
| trainable: trainable, | |||||
| name: name); | |||||
| return layer.apply(inputs); | return layer.apply(inputs); | ||||
| } | } | ||||
| @@ -0,0 +1,17 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| namespace Tensorflow.Keras.Engine | |||||
| { | |||||
| /// <summary> | |||||
| /// Specifies the ndim, dtype and shape of every input to a layer. | |||||
| /// </summary> | |||||
| public class InputSpec | |||||
| { | |||||
| public InputSpec(TF_DataType dtype = TF_DataType.DtInvalid) | |||||
| { | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -12,6 +12,77 @@ namespace Tensorflow.Keras.Engine | |||||
| /// </summary> | /// </summary> | ||||
| public class Layer : CheckpointableBase | public class Layer : CheckpointableBase | ||||
| { | { | ||||
| protected bool trainable; | |||||
| protected string _name; | |||||
| protected TF_DataType _dtype; | |||||
| protected Graph _graph; | |||||
| protected string _base_name; | |||||
| protected VariableScope _scope; | |||||
| /// <summary> | |||||
| /// A stateful layer is a layer whose updates are run during inference too, | |||||
| /// for instance stateful RNNs. | |||||
| /// </summary> | |||||
| protected bool stateful; | |||||
| /// <summary> | |||||
| /// Indicates whether `build` needs to be called upon layer call, to create | |||||
| /// the layer's weights. | |||||
| /// </summary> | |||||
| protected bool built; | |||||
| /// <summary> | |||||
| /// Provides information about which inputs are compatible with the layer. | |||||
| /// </summary> | |||||
| protected InputSpec input_spec; | |||||
| protected bool supports_masking; | |||||
| public Layer(bool trainable = true, | |||||
| string name = null, | |||||
| TF_DataType dtype = TF_DataType.DtInvalid) | |||||
| { | |||||
| this.trainable = trainable; | |||||
| this.stateful = false; | |||||
| this.built = false; | |||||
| this.supports_masking = false; | |||||
| _init_set_name(name); | |||||
| } | |||||
| public Tensor apply(Tensor inputs) | |||||
| { | |||||
| return __call__(inputs); | |||||
| } | |||||
| public Tensor __call__(Tensor inputs, | |||||
| VariableScope scope = null) | |||||
| { | |||||
| _set_scope(scope); | |||||
| _graph = ops._get_graph_from_inputs(new List<Tensor> { inputs }, graph: _graph); | |||||
| var scope_context_manager = tf.variable_scope(_scope); | |||||
| throw new NotImplementedException(""); | |||||
| } | |||||
| private void _init_set_name(string name) | |||||
| { | |||||
| if (string.IsNullOrEmpty(name)) | |||||
| (_name, _base_name) = _make_unique_name(); | |||||
| } | |||||
| private (string, string) _make_unique_name() | |||||
| { | |||||
| string base_name = "conv2d"; | |||||
| string name = base_layer_utils.unique_layer_name(base_name); | |||||
| return (name, base_name); | |||||
| } | |||||
| private void _set_scope(VariableScope scope = null) | |||||
| { | |||||
| if (_scope == null) | |||||
| { | |||||
| Python.with(tf.variable_scope(scope, default_name: _base_name), captured_scope => | |||||
| { | |||||
| _scope = captured_scope; | |||||
| }); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,26 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Text; | |||||
| namespace Tensorflow.Keras.Engine | |||||
| { | |||||
| public class base_layer_utils | |||||
| { | |||||
| /// <summary> | |||||
| /// Makes a layer name (or arbitrary string) unique within a TensorFlow graph. | |||||
| /// </summary> | |||||
| /// <param name="name"></param> | |||||
| /// <returns></returns> | |||||
| public static string unique_layer_name(string name) | |||||
| { | |||||
| int number = get_default_graph_uid_map(); | |||||
| return $"{name}_{number}"; | |||||
| } | |||||
| public static int get_default_graph_uid_map() | |||||
| { | |||||
| var graph = ops.get_default_graph(); | |||||
| return graph._next_id(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,10 +1,50 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Text; | using System.Text; | ||||
| using Tensorflow.Keras.Engine; | |||||
| using Tensorflow.Operations.Activation; | |||||
| namespace Tensorflow.Keras.Layers | namespace Tensorflow.Keras.Layers | ||||
| { | { | ||||
| public class Conv | |||||
| public class Conv : Layer | |||||
| { | { | ||||
| protected int rank; | |||||
| protected int filters; | |||||
| protected int[] kernel_size; | |||||
| protected int[] strides; | |||||
| protected string padding; | |||||
| protected string data_format; | |||||
| protected int[] dilation_rate; | |||||
| protected IActivation activation; | |||||
| protected bool use_bias; | |||||
| protected IInitializer kernel_initializer; | |||||
| protected IInitializer bias_initializer; | |||||
| public Conv(int rank, | |||||
| int filters, | |||||
| int[] kernel_size, | |||||
| int[] strides = null, | |||||
| string padding = "valid", | |||||
| string data_format = null, | |||||
| int[] dilation_rate = null, | |||||
| IActivation activation = null, | |||||
| bool use_bias = true, | |||||
| IInitializer kernel_initializer = null, | |||||
| IInitializer bias_initializer = null, | |||||
| bool trainable = true, | |||||
| string name = null) : base(trainable: trainable, name: name) | |||||
| { | |||||
| this.rank = rank; | |||||
| this.filters = filters; | |||||
| this.kernel_size = kernel_size; | |||||
| this.strides = strides; | |||||
| this.padding = padding; | |||||
| this.data_format = data_format; | |||||
| this.dilation_rate = dilation_rate; | |||||
| this.activation = activation; | |||||
| this.use_bias = use_bias; | |||||
| this.kernel_initializer = kernel_initializer; | |||||
| this.bias_initializer = bias_initializer; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -7,10 +7,6 @@ namespace Tensorflow.Keras.Layers | |||||
| { | { | ||||
| public class Conv2D : Conv | public class Conv2D : Conv | ||||
| { | { | ||||
| private int filters; | |||||
| private int[] kernel_size; | |||||
| private int[] strides; | |||||
| public Conv2D(int filters, | public Conv2D(int filters, | ||||
| int[] kernel_size, | int[] kernel_size, | ||||
| int[] strides = null, | int[] strides = null, | ||||
| @@ -22,14 +18,21 @@ namespace Tensorflow.Keras.Layers | |||||
| IInitializer kernel_initializer = null, | IInitializer kernel_initializer = null, | ||||
| IInitializer bias_initializer = null, | IInitializer bias_initializer = null, | ||||
| bool trainable = true, | bool trainable = true, | ||||
| string name = null) | |||||
| string name = null) : base(2, | |||||
| filters, | |||||
| kernel_size, | |||||
| strides: strides, | |||||
| padding: padding, | |||||
| data_format: data_format, | |||||
| dilation_rate: dilation_rate, | |||||
| activation: activation, | |||||
| use_bias: use_bias, | |||||
| kernel_initializer: kernel_initializer, | |||||
| bias_initializer: bias_initializer, | |||||
| trainable: trainable, | |||||
| name: name) | |||||
| { | { | ||||
| } | } | ||||
| public Tensor apply(Tensor inputs) | |||||
| { | |||||
| throw new NotImplementedException("apply"); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||