Browse Source

normalize_tuple, InputSpec

tags/v0.8.0
Oceania2018 6 years ago
parent
commit
79aaae2e16
13 changed files with 191 additions and 18 deletions
  1. +5
    -5
      TensorFlow.NET.sln
  2. +18
    -2
      src/TensorFlowNET.Core/APIs/tf.layers.cs
  3. +17
    -0
      src/TensorFlowNET.Core/Keras/Engine/InputSpec.cs
  4. +71
    -0
      src/TensorFlowNET.Core/Keras/Engine/Layer.cs
  5. +26
    -0
      src/TensorFlowNET.Core/Keras/Engine/base_layer_utils.cs
  6. +41
    -1
      src/TensorFlowNET.Core/Keras/Layers/Conv.cs
  7. +13
    -10
      src/TensorFlowNET.Core/Keras/Layers/Conv2D.cs
  8. +0
    -0
      src/TensorFlowNET.Visualization/Controllers/ValuesController.cs
  9. +0
    -0
      src/TensorFlowNET.Visualization/Program.cs
  10. +0
    -0
      src/TensorFlowNET.Visualization/Startup.cs
  11. +0
    -0
      src/TensorFlowNET.Visualization/TensorFlowNET.Visualization.csproj
  12. +0
    -0
      src/TensorFlowNET.Visualization/appsettings.Development.json
  13. +0
    -0
      src/TensorFlowNET.Visualization/appsettings.json

+ 5
- 5
TensorFlow.NET.sln View File

@@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Examples", "t
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\TensorFlowNET.Core\TensorFlowNET.Core.csproj", "{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}"
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
Global
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}.Release|Any CPU.ActiveCfg = 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
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 18
- 2
src/TensorFlowNET.Core/APIs/tf.layers.cs View File

@@ -19,14 +19,30 @@ namespace Tensorflow
int[] dilation_rate = null,
bool use_bias = true,
IActivation activation = null,
IInitializer kernel_initializer = null)
IInitializer kernel_initializer = null,
IInitializer bias_initializer = null,
bool trainable = true,
string name = null)
{
if (strides == null)
strides = new int[] { 1, 1 };
if (dilation_rate == null)
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);
}


+ 17
- 0
src/TensorFlowNET.Core/Keras/Engine/InputSpec.cs View File

@@ -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)
{

}
}
}

+ 71
- 0
src/TensorFlowNET.Core/Keras/Engine/Layer.cs View File

@@ -12,6 +12,77 @@ namespace Tensorflow.Keras.Engine
/// </summary>
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;
});
}
}
}
}

+ 26
- 0
src/TensorFlowNET.Core/Keras/Engine/base_layer_utils.cs View File

@@ -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();
}
}
}

+ 41
- 1
src/TensorFlowNET.Core/Keras/Layers/Conv.cs View File

@@ -1,10 +1,50 @@
using System;
using System.Collections.Generic;
using System.Text;
using Tensorflow.Keras.Engine;
using Tensorflow.Operations.Activation;

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;
}
}
}

+ 13
- 10
src/TensorFlowNET.Core/Keras/Layers/Conv2D.cs View File

@@ -7,10 +7,6 @@ namespace Tensorflow.Keras.Layers
{
public class Conv2D : Conv
{
private int filters;
private int[] kernel_size;
private int[] strides;

public Conv2D(int filters,
int[] kernel_size,
int[] strides = null,
@@ -22,14 +18,21 @@ namespace Tensorflow.Keras.Layers
IInitializer kernel_initializer = null,
IInitializer bias_initializer = null,
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");
}
}
}

TensorFlowNET.Visualization/Controllers/ValuesController.cs → src/TensorFlowNET.Visualization/Controllers/ValuesController.cs View File


TensorFlowNET.Visualization/Program.cs → src/TensorFlowNET.Visualization/Program.cs View File


TensorFlowNET.Visualization/Startup.cs → src/TensorFlowNET.Visualization/Startup.cs View File


TensorFlowNET.Visualization/TensorFlowNET.Visualization.csproj → src/TensorFlowNET.Visualization/TensorFlowNET.Visualization.csproj View File


TensorFlowNET.Visualization/appsettings.Development.json → src/TensorFlowNET.Visualization/appsettings.Development.json View File


TensorFlowNET.Visualization/appsettings.json → src/TensorFlowNET.Visualization/appsettings.json View File


Loading…
Cancel
Save