-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1149 from Wanglongzhi2001/master
feat: add Bidirectional layer
- Loading branch information
Showing
11 changed files
with
428 additions
and
18 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/BidirectionalArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Tensorflow.NumPy; | ||
|
||
namespace Tensorflow.Keras.ArgsDefinition | ||
{ | ||
public class BidirectionalArgs : AutoSerializeLayerArgs | ||
{ | ||
[JsonProperty("layer")] | ||
public ILayer Layer { get; set; } | ||
[JsonProperty("merge_mode")] | ||
public string? MergeMode { get; set; } | ||
[JsonProperty("backward_layer")] | ||
public ILayer BackwardLayer { get; set; } | ||
public NDArray Weights { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/TensorFlowNET.Core/Keras/ArgsDefinition/Rnn/WrapperArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
|
||
|
||
namespace Tensorflow.Keras.ArgsDefinition | ||
{ | ||
public class WrapperArgs : AutoSerializeLayerArgs | ||
{ | ||
[JsonProperty("layer")] | ||
public ILayer Layer { get; set; } | ||
|
||
public WrapperArgs(ILayer layer) | ||
{ | ||
Layer = layer; | ||
} | ||
|
||
public static implicit operator WrapperArgs(BidirectionalArgs args) | ||
=> new WrapperArgs(args.Layer); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text; | ||
using Tensorflow.Keras.ArgsDefinition; | ||
using Tensorflow.Keras.Saving; | ||
|
||
namespace Tensorflow.Keras.Layers | ||
{ | ||
/// <summary> | ||
/// Abstract wrapper base class. Wrappers take another layer and augment it in various ways. | ||
/// Do not use this class as a layer, it is only an abstract base class. | ||
/// Two usable wrappers are the `TimeDistributed` and `Bidirectional` wrappers. | ||
/// </summary> | ||
public abstract class Wrapper: Layer | ||
{ | ||
public ILayer _layer; | ||
public Wrapper(WrapperArgs args):base(args) | ||
{ | ||
_layer = args.Layer; | ||
} | ||
|
||
public virtual void Build(KerasShapesWrapper input_shape) | ||
{ | ||
if (!_layer.Built) | ||
{ | ||
_layer.build(input_shape); | ||
} | ||
built = true; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.