Browse Source

fix max_pooling2d name_scope.

tags/v0.9
Oceania2018 6 years ago
parent
commit
f0d1ee8db4
7 changed files with 52 additions and 44 deletions
  1. +7
    -4
      src/TensorFlowNET.Core/APIs/tf.init.cs
  2. +4
    -4
      src/TensorFlowNET.Core/Keras/Layers/Layer.cs
  3. +24
    -24
      src/TensorFlowNET.Core/Layers/Layer.cs
  4. +6
    -2
      src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs
  5. +5
    -8
      src/TensorFlowNET.Core/TensorFlowNET.Core.csproj
  6. +1
    -1
      src/TensorFlowNET.Core/Variables/variable_scope.py.cs
  7. +5
    -1
      test/TensorFlowNET.Examples/TextProcess/CnnTextClassification.cs

+ 7
- 4
src/TensorFlowNET.Core/APIs/tf.init.cs View File

@@ -15,10 +15,12 @@ namespace Tensorflow
public static variable_scope variable_scope(string name,
string default_name = null,
Tensor[] values = null,
bool auxiliary_name_scope = true) => new variable_scope(name,
default_name,
bool? reuse = null,
bool auxiliary_name_scope = true) => new variable_scope(name,
default_name,
values,
auxiliary_name_scope);
reuse: reuse,
auxiliary_name_scope: auxiliary_name_scope);

public static variable_scope variable_scope(VariableScope scope,
string default_name = null,
@@ -27,7 +29,8 @@ namespace Tensorflow
bool auxiliary_name_scope = true) => new variable_scope(scope,
default_name,
values,
auxiliary_name_scope);
reuse: reuse,
auxiliary_name_scope: auxiliary_name_scope);

public static IInitializer truncated_normal_initializer(float mean = 0.0f,
float stddev = 1.0f,


+ 4
- 4
src/TensorFlowNET.Core/Keras/Layers/Layer.cs View File

@@ -108,11 +108,11 @@ namespace Tensorflow.Keras.Layers
// Build layer if applicable (if the `build` method has been
// overridden).
_maybe_build(inputs[0]);
});

outputs = call(inputs[0], training: training);
_handle_activity_regularization(inputs[0], outputs);
_set_mask_metadata(inputs[0], outputs, null);
outputs = call(inputs[0], training: training);
_handle_activity_regularization(inputs[0], outputs);
_set_mask_metadata(inputs[0], outputs, null);
});
}

return outputs;


+ 24
- 24
src/TensorFlowNET.Core/Layers/Layer.cs View File

@@ -48,6 +48,7 @@ namespace Tensorflow.Layers
else
{
scope_context_manager = tf.variable_scope(_scope,
reuse: _reuse,
auxiliary_name_scope: false);
}

@@ -123,34 +124,33 @@ namespace Tensorflow.Layers

_set_scope();
var reuse = built || (_reuse != null && _reuse.Value);
return Python.with(tf.variable_scope(_scope,
reuse: reuse,
return with(tf.variable_scope(_scope,
reuse: reuse,
auxiliary_name_scope: false), scope =>
{
_current_scope = scope;
return Python.with(ops.name_scope(_name_scope()), delegate
{
var variable = base.add_weight(name,
shape,
dtype: dtype,
initializer: initializer,
trainable: trainable,
getter: (name1, shape1, dtype1, initializer1, trainable1) =>
{
return tf.get_variable(name1,
shape: new TensorShape(shape1),
dtype: dtype1,
initializer: initializer1,
trainable: trainable1);
});

if(init_graph != null)
_current_scope = scope;
return with(ops.name_scope(_name_scope()), delegate
{
var trainable_variables = variables.trainable_variables();
}
return variable;
var variable = base.add_weight(name,
shape,
dtype: dtype,
initializer: initializer,
trainable: trainable,
getter: (name1, shape1, dtype1, initializer1, trainable1) =>
{
return tf.get_variable(name1,
shape: new TensorShape(shape1),
dtype: dtype1,
initializer: initializer1,
trainable: trainable1);
});

//if (init_graph != null)
//var trainable_variables = variables.trainable_variables();
return variable;
});
});
});
}




+ 6
- 2
src/TensorFlowNET.Core/Operations/NnOps/MaxPoolFunction.cs View File

@@ -5,6 +5,9 @@ using static Tensorflow.Python;

namespace Tensorflow.Operations
{
/// <summary>
/// Performs the max pooling on the input.
/// </summary>
public class MaxPoolFunction : IPoolFunction
{
public Tensor Apply(Tensor value,
@@ -14,8 +17,9 @@ namespace Tensorflow.Operations
string data_format = "NHWC",
string name = null)
{
return with(ops.name_scope(name, "MaxPool", new { value }), scope => {

return with(ops.name_scope(name, "MaxPool", value), scope =>
{
name = scope;
value = ops.convert_to_tensor(value, name: "input");
return gen_nn_ops.max_pool(
value,


+ 5
- 8
src/TensorFlowNET.Core/TensorFlowNET.Core.csproj View File

@@ -5,7 +5,7 @@
<AssemblyName>TensorFlow.NET</AssemblyName>
<RootNamespace>Tensorflow</RootNamespace>
<TargetTensorFlow>1.14.0</TargetTensorFlow>
<Version>0.8.0</Version>
<Version>0.8.1</Version>
<Authors>Haiping Chen</Authors>
<Company>SciSharp STACK</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -17,15 +17,12 @@
<PackageTags>TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET, C#</PackageTags>
<Description>Google's TensorFlow full binding in .NET Standard.
Docs: https://tensorflownet.readthedocs.io</Description>
<AssemblyVersion>0.8.0.0</AssemblyVersion>
<PackageReleaseNotes>Changes since v0.7:
<AssemblyVersion>0.8.1.0</AssemblyVersion>
<PackageReleaseNotes>Changes since v0.8:

Add XOR example.
Add KMeans example.
Add Object Detection example.
Add Word2Vec example.</PackageReleaseNotes>
Removed global static graph instance.</PackageReleaseNotes>
<LangVersion>7.2</LangVersion>
<FileVersion>0.8.0.0</FileVersion>
<FileVersion>0.8.1.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">


+ 1
- 1
src/TensorFlowNET.Core/Variables/variable_scope.py.cs View File

@@ -107,7 +107,7 @@ namespace Tensorflow
if (_name != null || _scope != null)
{
var name_scope = _name == null ? _scope.name.Split('/').Last() : _name;
if (name_scope != null || current_name_scope != null)
if (current_name_scope == null)
current_name_scope = ops.name_scope(name_scope);
current_name_scope.__enter__();
var current_name_scope_name = current_name_scope;


+ 5
- 1
test/TensorFlowNET.Examples/TextProcess/CnnTextClassification.cs View File

@@ -174,7 +174,8 @@ namespace TensorFlowNET.Examples
x_emb = tf.expand_dims(x_emb, -1);
});

for(int len = 0; len < filter_sizes.Rank; len++)
var pooled_outputs = new List<Tensor>();
for (int len = 0; len < filter_sizes.Rank; len++)
{
int filter_size = filter_sizes.GetLength(len);
var conv = tf.layers.conv2d(
@@ -190,8 +191,11 @@ namespace TensorFlowNET.Examples
pool_size: new[] { document_max_len - filter_size + 1, 1 },
strides: new[] { 1, 1 },
padding: "VALID");

pooled_outputs.Add(pool);
}

// var h_pool = tf.concat(pooled_outputs, 3);
return graph;
}



Loading…
Cancel
Save