From d3b681e9097bbe0ab894fc134f27118abc803c6e Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 12 Sep 2020 17:45:46 -0500 Subject: [PATCH] fix unit test. --- src/TensorFlowNET.Core/Keras/Engine/Layer.cs | 4 ---- src/TensorFlowNET.Core/Layers/Layer.cs | 7 +++---- src/TensorFlowNET.Core/Operations/NnOps/BasicLSTMCell.cs | 4 ++-- test/TensorFlowNET.UnitTest/Keras/LayersTest.cs | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/TensorFlowNET.Core/Keras/Engine/Layer.cs b/src/TensorFlowNET.Core/Keras/Engine/Layer.cs index 6f0b2294..aec7471b 100644 --- a/src/TensorFlowNET.Core/Keras/Engine/Layer.cs +++ b/src/TensorFlowNET.Core/Keras/Engine/Layer.cs @@ -138,10 +138,6 @@ namespace Tensorflow.Keras.Engine { nameScope = name; } - else - { - throw new NotImplementedException(""); - } // using var graph = tf.keras.backend.get_graph().as_default(); if (!inputs.IsEagerTensor) diff --git a/src/TensorFlowNET.Core/Layers/Layer.cs b/src/TensorFlowNET.Core/Layers/Layer.cs index ae3157b0..b9d73cf8 100644 --- a/src/TensorFlowNET.Core/Layers/Layer.cs +++ b/src/TensorFlowNET.Core/Layers/Layer.cs @@ -83,20 +83,19 @@ namespace Tensorflow.Layers auxiliary_name_scope: false); } - Tensor[] outputs = null; + Tensor outputs = null; tf_with(scope_context_manager, scope2 => { _current_scope = scope2; // Actually call layer - /*outputs = base.Apply(new Tensor[] { inputs }, - is_training: training);*/ + outputs = base.Apply(inputs); }); // Update global default collections. _add_elements_to_collection(updates.ToArray(), new string[] { tf.GraphKeys.UPDATE_OPS }); - return outputs; + return new Tensor[] { outputs }; } protected virtual void _add_elements_to_collection(Operation[] elements, string[] collection_list) diff --git a/src/TensorFlowNET.Core/Operations/NnOps/BasicLSTMCell.cs b/src/TensorFlowNET.Core/Operations/NnOps/BasicLSTMCell.cs index 35d1a026..37f21377 100644 --- a/src/TensorFlowNET.Core/Operations/NnOps/BasicLSTMCell.cs +++ b/src/TensorFlowNET.Core/Operations/NnOps/BasicLSTMCell.cs @@ -87,8 +87,8 @@ namespace Tensorflow // array_ops.split(value: state, num_or_size_splits: 2, axis: one); throw new NotImplementedException("BasicLstmCell call"); } - var gate_inputs = math_ops.matmul(array_ops.concat(new[] { inputs, h }, 1), _kernel as RefVariable); - gate_inputs = nn_ops.bias_add(gate_inputs, _bias as RefVariable); + var gate_inputs = math_ops.matmul(array_ops.concat(new[] { inputs, h }, 1), _kernel.AsTensor()); + gate_inputs = nn_ops.bias_add(gate_inputs, _bias.AsTensor()); // i = input_gate, j = new_input, f = forget_gate, o = output_gate var tensors = array_ops.split(value: gate_inputs, num_split: 4, axis: one); diff --git a/test/TensorFlowNET.UnitTest/Keras/LayersTest.cs b/test/TensorFlowNET.UnitTest/Keras/LayersTest.cs index f59fab8c..78ab8816 100644 --- a/test/TensorFlowNET.UnitTest/Keras/LayersTest.cs +++ b/test/TensorFlowNET.UnitTest/Keras/LayersTest.cs @@ -52,7 +52,7 @@ namespace TensorFlowNET.UnitTest.Keras // Create a `Sequential` model and add a Dense layer as the first layer. var model = tf.keras.Sequential(); model.add(tf.keras.Input(shape: 16)); - model.add(tf.keras.layers.Dense(32, activation: tf.keras.activations.Relu)); + model.add(tf.keras.layers.Dense(32, activation: "relu")); // Now the model will take as input arrays of shape (None, 16) // and output arrays of shape (None, 32). // Note that after the first layer, you don't need to specify