Browse Source

Merge pull request #1144 from Wanglongzhi2001/master

fix: fix the bug of load LSTM model and add test
tags/v0.110.4-Transformer-Model
Haiping GitHub 2 years ago
parent
commit
d452d8c2d7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 81 additions and 40 deletions
  1. +1
    -1
      src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/GRUCellArgs.cs
  2. +1
    -1
      src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/LSTMArgs.cs
  3. +1
    -1
      src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/LSTMCellArgs.cs
  4. +9
    -3
      src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/RNNArgs.cs
  5. +1
    -1
      src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/RnnOptionalArgs.cs
  6. +1
    -1
      src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/SimpleRNNArgs.cs
  7. +1
    -1
      src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/SimpleRNNCellArgs.cs
  8. +2
    -2
      src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/StackedRNNCellsArgs.cs
  9. +1
    -1
      src/TensorFlowNET.Core/Keras/Layers/ILayersApi.cs
  10. +1
    -1
      src/TensorFlowNET.Core/Keras/Layers/Rnn/IRnnCell.cs
  11. +1
    -1
      src/TensorFlowNET.Core/Keras/Layers/Rnn/IStackedRnnCells.cs
  12. +1
    -2
      src/TensorFlowNET.Core/Operations/NnOps/RNNCell.cs
  13. +3
    -1
      src/TensorFlowNET.Core/ops.cs
  14. +1
    -2
      src/TensorFlowNET.Keras/Layers/LayersApi.cs
  15. +1
    -1
      src/TensorFlowNET.Keras/Layers/Rnn/DropoutRNNCellMixin.cs
  16. +1
    -2
      src/TensorFlowNET.Keras/Layers/Rnn/GRUCell.cs
  17. +2
    -2
      src/TensorFlowNET.Keras/Layers/Rnn/LSTM.cs
  18. +2
    -2
      src/TensorFlowNET.Keras/Layers/Rnn/LSTMCell.cs
  19. +2
    -2
      src/TensorFlowNET.Keras/Layers/Rnn/RNN.cs
  20. +1
    -1
      src/TensorFlowNET.Keras/Layers/Rnn/RnnBase.cs
  21. +2
    -2
      src/TensorFlowNET.Keras/Layers/Rnn/SimpleRNN.cs
  22. +2
    -2
      src/TensorFlowNET.Keras/Layers/Rnn/SimpleRNNCell.cs
  23. +2
    -2
      src/TensorFlowNET.Keras/Layers/Rnn/StackedRNNCells.cs
  24. +0
    -1
      src/TensorFlowNET.Keras/Saving/KerasObjectLoader.cs
  25. +1
    -1
      src/TensorFlowNET.Keras/Saving/SavedModel/serialized_attributes.cs
  26. +1
    -1
      src/TensorFlowNET.Keras/Utils/RnnUtils.cs
  27. +1
    -0
      test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/fingerprint.pb
  28. +7
    -0
      test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/keras_metadata.pb
  29. BIN
      test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/saved_model.pb
  30. BIN
      test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/variables/variables.data-00000-of-00001
  31. BIN
      test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/variables/variables.index
  32. +1
    -1
      test/TensorFlowNET.Keras.UnitTest/Layers/Rnn.Test.cs
  33. +14
    -1
      test/TensorFlowNET.Keras.UnitTest/Model/ModelLoadTest.cs
  34. +16
    -0
      test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj

+ 1
- 1
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/GRUCellArgs.cs View File

@@ -3,7 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;


namespace Tensorflow.Keras.ArgsDefinition.Rnn
namespace Tensorflow.Keras.ArgsDefinition
{ {
public class GRUCellArgs : AutoSerializeLayerArgs public class GRUCellArgs : AutoSerializeLayerArgs
{ {


+ 1
- 1
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/LSTMArgs.cs View File

@@ -1,4 +1,4 @@
namespace Tensorflow.Keras.ArgsDefinition.Rnn
namespace Tensorflow.Keras.ArgsDefinition
{ {
public class LSTMArgs : RNNArgs public class LSTMArgs : RNNArgs
{ {


+ 1
- 1
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/LSTMCellArgs.cs View File

@@ -1,7 +1,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using static Tensorflow.Binding; using static Tensorflow.Binding;


namespace Tensorflow.Keras.ArgsDefinition.Rnn
namespace Tensorflow.Keras.ArgsDefinition
{ {
// TODO: complete the implementation // TODO: complete the implementation
public class LSTMCellArgs : AutoSerializeLayerArgs public class LSTMCellArgs : AutoSerializeLayerArgs


+ 9
- 3
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/RNNArgs.cs View File

@@ -1,8 +1,8 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Collections.Generic; using System.Collections.Generic;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Layers;


namespace Tensorflow.Keras.ArgsDefinition.Rnn
namespace Tensorflow.Keras.ArgsDefinition
{ {
// TODO(Rinne): add regularizers. // TODO(Rinne): add regularizers.
public class RNNArgs : AutoSerializeLayerArgs public class RNNArgs : AutoSerializeLayerArgs
@@ -23,16 +23,22 @@ namespace Tensorflow.Keras.ArgsDefinition.Rnn
public int? InputDim { get; set; } public int? InputDim { get; set; }
public int? InputLength { get; set; } public int? InputLength { get; set; }
// TODO: Add `num_constants` and `zero_output_for_mask`. // TODO: Add `num_constants` and `zero_output_for_mask`.
[JsonProperty("units")]
public int Units { get; set; } public int Units { get; set; }
[JsonProperty("activation")]
public Activation Activation { get; set; } public Activation Activation { get; set; }
[JsonProperty("recurrent_activation")]
public Activation RecurrentActivation { get; set; } public Activation RecurrentActivation { get; set; }
[JsonProperty("use_bias")]
public bool UseBias { get; set; } = true; public bool UseBias { get; set; } = true;
public IInitializer KernelInitializer { get; set; } public IInitializer KernelInitializer { get; set; }
public IInitializer RecurrentInitializer { get; set; } public IInitializer RecurrentInitializer { get; set; }
public IInitializer BiasInitializer { get; set; } public IInitializer BiasInitializer { get; set; }
[JsonProperty("dropout")]
public float Dropout { get; set; } = .0f; public float Dropout { get; set; } = .0f;
[JsonProperty("zero_output_for_mask")]
public bool ZeroOutputForMask { get; set; } = false; public bool ZeroOutputForMask { get; set; } = false;
[JsonProperty("recurrent_dropout")]
public float RecurrentDropout { get; set; } = .0f; public float RecurrentDropout { get; set; } = .0f;
} }
} }

+ 1
- 1
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/RnnOptionalArgs.cs View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;


namespace Tensorflow.Keras.ArgsDefinition.Rnn
namespace Tensorflow.Keras.ArgsDefinition
{ {
public class RnnOptionalArgs: IOptionalArgs public class RnnOptionalArgs: IOptionalArgs
{ {


+ 1
- 1
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/SimpleRNNArgs.cs View File

@@ -1,4 +1,4 @@
namespace Tensorflow.Keras.ArgsDefinition.Rnn
namespace Tensorflow.Keras.ArgsDefinition
{ {
public class SimpleRNNArgs : RNNArgs public class SimpleRNNArgs : RNNArgs
{ {


+ 1
- 1
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/SimpleRNNCellArgs.cs View File

@@ -1,6 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;


namespace Tensorflow.Keras.ArgsDefinition.Rnn
namespace Tensorflow.Keras.ArgsDefinition
{ {
public class SimpleRNNCellArgs: AutoSerializeLayerArgs public class SimpleRNNCellArgs: AutoSerializeLayerArgs
{ {


+ 2
- 2
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/StackedRNNCellsArgs.cs View File

@@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Layers;


namespace Tensorflow.Keras.ArgsDefinition.Rnn
namespace Tensorflow.Keras.ArgsDefinition
{ {
public class StackedRNNCellsArgs : LayerArgs public class StackedRNNCellsArgs : LayerArgs
{ {


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

@@ -1,7 +1,7 @@
using System; using System;
using Tensorflow.Framework.Models; using Tensorflow.Framework.Models;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Layers;
using Tensorflow.NumPy; using Tensorflow.NumPy;
using static Google.Protobuf.Reflection.FieldDescriptorProto.Types; using static Google.Protobuf.Reflection.FieldDescriptorProto.Types;




+ 1
- 1
src/TensorFlowNET.Core/Keras/Layers/Rnn/IRnnCell.cs View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
public interface IRnnCell: ILayer public interface IRnnCell: ILayer
{ {


+ 1
- 1
src/TensorFlowNET.Core/Keras/Layers/Rnn/IStackedRnnCells.cs View File

@@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
public interface IStackedRnnCells : IRnnCell public interface IStackedRnnCells : IRnnCell
{ {


+ 1
- 2
src/TensorFlowNET.Core/Operations/NnOps/RNNCell.cs View File

@@ -19,9 +19,8 @@ using System.Collections.Generic;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;
using Tensorflow.Keras; using Tensorflow.Keras;
using Tensorflow.Keras.ArgsDefinition; using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Layers;
using Tensorflow.Keras.Saving; using Tensorflow.Keras.Saving;
using Tensorflow.NumPy; using Tensorflow.NumPy;
using Tensorflow.Operations; using Tensorflow.Operations;


+ 3
- 1
src/TensorFlowNET.Core/ops.cs View File

@@ -571,7 +571,9 @@ namespace Tensorflow
if (tf.Context.executing_eagerly()) if (tf.Context.executing_eagerly())
return true; return true;
else else
throw new NotImplementedException("");
// TODO(Wanglongzhi2001), implement the false case
return true;
//throw new NotImplementedException("");
} }


public static bool inside_function() public static bool inside_function()


+ 1
- 2
src/TensorFlowNET.Keras/Layers/LayersApi.cs View File

@@ -2,9 +2,8 @@
using Tensorflow.Framework.Models; using Tensorflow.Framework.Models;
using Tensorflow.Keras.ArgsDefinition; using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.ArgsDefinition.Core; using Tensorflow.Keras.ArgsDefinition.Core;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Layers;
using Tensorflow.NumPy; using Tensorflow.NumPy;
using static Tensorflow.Binding; using static Tensorflow.Binding;
using static Tensorflow.KerasApi; using static Tensorflow.KerasApi;


+ 1
- 1
src/TensorFlowNET.Keras/Layers/Rnn/DropoutRNNCellMixin.cs View File

@@ -6,7 +6,7 @@ using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Utils; using Tensorflow.Keras.Utils;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
public abstract class DropoutRNNCellMixin: Layer, IRnnCell public abstract class DropoutRNNCellMixin: Layer, IRnnCell
{ {


+ 1
- 2
src/TensorFlowNET.Keras/Layers/Rnn/GRUCell.cs View File

@@ -3,12 +3,11 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using Tensorflow.Keras.ArgsDefinition; using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Common.Extensions; using Tensorflow.Common.Extensions;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;
using Tensorflow.Keras.Saving; using Tensorflow.Keras.Saving;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
/// <summary> /// <summary>
/// Cell class for the GRU layer. /// Cell class for the GRU layer.


+ 2
- 2
src/TensorFlowNET.Keras/Layers/Rnn/LSTM.cs View File

@@ -1,10 +1,10 @@
using System.Linq; using System.Linq;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;
using Tensorflow.Common.Extensions; using Tensorflow.Common.Extensions;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
/// <summary> /// <summary>
/// Long Short-Term Memory layer - Hochreiter 1997. /// Long Short-Term Memory layer - Hochreiter 1997.


+ 2
- 2
src/TensorFlowNET.Keras/Layers/Rnn/LSTMCell.cs View File

@@ -3,12 +3,12 @@ using Serilog.Core;
using System.Diagnostics; using System.Diagnostics;
using Tensorflow.Common.Extensions; using Tensorflow.Common.Extensions;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Saving; using Tensorflow.Keras.Saving;
using Tensorflow.Keras.Utils; using Tensorflow.Keras.Utils;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
/// <summary> /// <summary>
/// Cell class for the LSTM layer. /// Cell class for the LSTM layer.


+ 2
- 2
src/TensorFlowNET.Keras/Layers/Rnn/RNN.cs View File

@@ -3,7 +3,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Tensorflow.Keras.ArgsDefinition; using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Saving; using Tensorflow.Keras.Saving;
using Tensorflow.Util; using Tensorflow.Util;
@@ -14,7 +13,7 @@ using Tensorflow.Common.Types;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
// from tensorflow.python.distribute import distribution_strategy_context as ds_context; // from tensorflow.python.distribute import distribution_strategy_context as ds_context;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
/// <summary> /// <summary>
/// Base class for recurrent layers. /// Base class for recurrent layers.
@@ -185,6 +184,7 @@ namespace Tensorflow.Keras.Layers.Rnn


public override void build(KerasShapesWrapper input_shape) public override void build(KerasShapesWrapper input_shape)
{ {
_buildInputShape = input_shape;
input_shape = new KerasShapesWrapper(input_shape.Shapes[0]); input_shape = new KerasShapesWrapper(input_shape.Shapes[0]);


InputSpec get_input_spec(Shape shape) InputSpec get_input_spec(Shape shape)


+ 1
- 1
src/TensorFlowNET.Keras/Layers/Rnn/RnnBase.cs View File

@@ -4,7 +4,7 @@ using System.Text;
using Tensorflow.Keras.ArgsDefinition; using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
public abstract class RnnBase: Layer public abstract class RnnBase: Layer
{ {


+ 2
- 2
src/TensorFlowNET.Keras/Layers/Rnn/SimpleRNN.cs View File

@@ -1,11 +1,11 @@
using System.Data; using System.Data;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Saving; using Tensorflow.Keras.Saving;
using Tensorflow.Operations.Activation; using Tensorflow.Operations.Activation;
using static HDF.PInvoke.H5Z; using static HDF.PInvoke.H5Z;
using static Tensorflow.ApiDef.Types; using static Tensorflow.ApiDef.Types;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
public class SimpleRNN : RNN public class SimpleRNN : RNN
{ {


+ 2
- 2
src/TensorFlowNET.Keras/Layers/Rnn/SimpleRNNCell.cs View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Saving; using Tensorflow.Keras.Saving;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;
@@ -9,7 +9,7 @@ using Tensorflow.Common.Extensions;
using Tensorflow.Keras.Utils; using Tensorflow.Keras.Utils;
using Tensorflow.Graphs; using Tensorflow.Graphs;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
/// <summary> /// <summary>
/// Cell class for SimpleRNN. /// Cell class for SimpleRNN.


+ 2
- 2
src/TensorFlowNET.Keras/Layers/Rnn/StackedRNNCells.cs View File

@@ -3,12 +3,12 @@ using System.ComponentModel;
using System.Linq; using System.Linq;
using Tensorflow.Common.Extensions; using Tensorflow.Common.Extensions;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;
using Tensorflow.Keras.ArgsDefinition.Rnn;
using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Saving; using Tensorflow.Keras.Saving;
using Tensorflow.Keras.Utils; using Tensorflow.Keras.Utils;


namespace Tensorflow.Keras.Layers.Rnn
namespace Tensorflow.Keras.Layers
{ {
public class StackedRNNCells : Layer, IRnnCell public class StackedRNNCells : Layer, IRnnCell
{ {


+ 0
- 1
src/TensorFlowNET.Keras/Saving/KerasObjectLoader.cs View File

@@ -13,7 +13,6 @@ using Tensorflow.Framework.Models;
using Tensorflow.Keras.ArgsDefinition; using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Layers; using Tensorflow.Keras.Layers;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Losses; using Tensorflow.Keras.Losses;
using Tensorflow.Keras.Metrics; using Tensorflow.Keras.Metrics;
using Tensorflow.Keras.Saving.SavedModel; using Tensorflow.Keras.Saving.SavedModel;


+ 1
- 1
src/TensorFlowNET.Keras/Saving/SavedModel/serialized_attributes.cs View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Layers;
using Tensorflow.Keras.Metrics; using Tensorflow.Keras.Metrics;
using Tensorflow.Train; using Tensorflow.Train;




+ 1
- 1
src/TensorFlowNET.Keras/Utils/RnnUtils.cs View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Layers;
using Tensorflow.Common.Extensions; using Tensorflow.Common.Extensions;


namespace Tensorflow.Keras.Utils namespace Tensorflow.Keras.Utils


+ 1
- 0
test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/fingerprint.pb View File

@@ -0,0 +1 @@
כ�„��÷»µףזּ�כ•�ֽ‰ה ¥• החנהµ גל־£₪גּֿע(ׁהױ¼��בפ2

+ 7
- 0
test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/keras_metadata.pb View File

@@ -0,0 +1,7 @@

Õ&root"_tf_keras_sequential*°&{"name": "sequential", "trainable": true, "expects_training_arg": true, "dtype": "float32", "batch_input_shape": null, "must_restore_from_config": false, "preserve_input_structure_in_config": false, "autocast": false, "class_name": "Sequential", "config": {"name": "sequential", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 5, 3]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "input_1"}}, {"class_name": "LSTM", "config": {"name": "lstm", "trainable": true, "dtype": "float32", "return_sequences": false, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 32, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 1}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}, "shared_object_id": 2}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 3}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}}, {"class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 1, "activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}, "shared_object_id": 9, "input_spec": [{"class_name": "InputSpec", "config": {"dtype": null, "shape": {"class_name": "__tuple__", "items": [null, 5, 3]}, "ndim": 3, "max_ndim": null, "min_ndim": null, "axes": {}}}], "build_input_shape": {"class_name": "TensorShape", "items": [null, 5, 3]}, "is_graph_network": true, "full_save_spec": {"class_name": "__tuple__", "items": [[{"class_name": "TypeSpec", "type_spec": "tf.TensorSpec", "serialized": [{"class_name": "TensorShape", "items": [null, 5, 3]}, "float32", "input_1"]}], {}]}, "save_spec": {"class_name": "TypeSpec", "type_spec": "tf.TensorSpec", "serialized": [{"class_name": "TensorShape", "items": [null, 5, 3]}, "float32", "input_1"]}, "keras_version": "2.12.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 5, 3]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "input_1"}, "shared_object_id": 0}, {"class_name": "LSTM", "config": {"name": "lstm", "trainable": true, "dtype": "float32", "return_sequences": false, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 32, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 1}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}, "shared_object_id": 2}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 3}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}, "shared_object_id": 5}, {"class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 1, "activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 6}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 7}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 8}]}}, "training_config": {"loss": "binary_crossentropy", "metrics": [[{"class_name": "MeanMetricWrapper", "config": {"name": "accuracy", "dtype": "float32", "fn": "binary_accuracy"}, "shared_object_id": 11}]], "weighted_metrics": null, "loss_weights": null, "optimizer_config": {"class_name": "Custom>Adam", "config": {"name": "Adam", "weight_decay": null, "clipnorm": null, "global_clipnorm": null, "clipvalue": null, "use_ema": false, "ema_momentum": 0.99, "ema_overwrite_frequency": null, "jit_compile": false, "is_legacy_optimizer": false, "learning_rate": 0.0010000000474974513, "beta_1": 0.9, "beta_2": 0.999, "epsilon": 1e-07, "amsgrad": false}}}}2
Ý root.layer_with_weights-0"_tf_keras_rnn_layer*¢ {"name": "lstm", "trainable": true, "expects_training_arg": true, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "preserve_input_structure_in_config": false, "autocast": true, "class_name": "LSTM", "config": {"name": "lstm", "trainable": true, "dtype": "float32", "return_sequences": false, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 32, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 1}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}, "shared_object_id": 2}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 3}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}, "shared_object_id": 5, "input_spec": [{"class_name": "InputSpec", "config": {"dtype": null, "shape": {"class_name": "__tuple__", "items": [null, null, 3]}, "ndim": 3, "max_ndim": null, "min_ndim": null, "axes": {}}, "shared_object_id": 12}], "build_input_shape": {"class_name": "TensorShape", "items": [null, 5, 3]}}2
‚root.layer_with_weights-1"_tf_keras_layer*Ë{"name": "dense", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "preserve_input_structure_in_config": false, "autocast": true, "class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 1, "activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 6}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 7}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 8, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 32}}, "shared_object_id": 13}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 32]}}2
ìroot.layer_with_weights-0.cell"_tf_keras_layer*°{"name": "lstm_cell", "trainable": true, "expects_training_arg": true, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "preserve_input_structure_in_config": false, "autocast": true, "class_name": "LSTMCell", "config": {"name": "lstm_cell", "trainable": true, "dtype": "float32", "units": 32, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 1}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}, "shared_object_id": 2}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 3}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}, "shared_object_id": 4, "build_input_shape": {"class_name": "__tuple__", "items": [null, 3]}}2
¹Rroot.keras_api.metrics.0"_tf_keras_metric*‚{"class_name": "Mean", "name": "loss", "dtype": "float32", "config": {"name": "loss", "dtype": "float32"}, "shared_object_id": 14}2
çSroot.keras_api.metrics.1"_tf_keras_metric*°{"class_name": "MeanMetricWrapper", "name": "accuracy", "dtype": "float32", "config": {"name": "accuracy", "dtype": "float32", "fn": "binary_accuracy"}, "shared_object_id": 11}2

BIN
test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/saved_model.pb View File


BIN
test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/variables/variables.data-00000-of-00001 View File


BIN
test/TensorFlowNET.Keras.UnitTest/Assets/lstm_from_sequential/variables/variables.index View File


+ 1
- 1
test/TensorFlowNET.Keras.UnitTest/Layers/Rnn.Test.cs View File

@@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Tensorflow.Common.Types; using Tensorflow.Common.Types;
using Tensorflow.Keras.Engine; using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Layers.Rnn;
using Tensorflow.Keras.Layers;
using Tensorflow.Keras.Saving; using Tensorflow.Keras.Saving;
using Tensorflow.NumPy; using Tensorflow.NumPy;
using Tensorflow.Train; using Tensorflow.Train;


+ 14
- 1
test/TensorFlowNET.Keras.UnitTest/Model/ModelLoadTest.cs View File

@@ -1,5 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq; using System.Linq;
using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Optimizers; using Tensorflow.Keras.Optimizers;
using Tensorflow.Keras.UnitTest.Helpers; using Tensorflow.Keras.UnitTest.Helpers;
using Tensorflow.NumPy; using Tensorflow.NumPy;
@@ -79,6 +81,17 @@ public class ModelLoadTest
model.fit(dataset.Train.Data, dataset.Train.Labels, batch_size, num_epochs); model.fit(dataset.Train.Data, dataset.Train.Labels, batch_size, num_epochs);
} }


[TestMethod]
public void LSTMLoad()
{
var model = tf.keras.models.load_model(@"Assets/lstm_from_sequential");
model.summary();
model.compile(tf.keras.optimizers.Adam(), tf.keras.losses.MeanSquaredError(), new string[] { "accuracy" });
var inputs = tf.random.normal(shape: (10, 5, 3));
var outputs = tf.random.normal(shape: (10, 1));
model.fit(inputs.numpy(), outputs.numpy(), batch_size: 10, epochs: 5, workers: 16, use_multiprocessing: true);
}

[Ignore] [Ignore]
[TestMethod] [TestMethod]
public void VGG19() public void VGG19()


+ 16
- 0
test/TensorFlowNET.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj View File

@@ -65,6 +65,22 @@
<None Update="Assets\python_func_model\variables\variables.index"> <None Update="Assets\python_func_model\variables\variables.index">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>

<None Update="Assets\lstm_from_sequential\fingerprint.pb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\lstm_from_sequential\keras_metadata.pb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\lstm_from_sequential\saved_model.pb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\lstm_from_sequential\variables\variables.data-00000-of-00001">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\lstm_from_sequential\variables\variables.index">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup> </ItemGroup>


</Project> </Project>

Loading…
Cancel
Save