| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 675b93a commit a0df810
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -503,7 +503,7 @@ public static TF_DataType GetDataType(this object data) | |||
| 503 | 503 | case Tensors tensors: | |
| 504 | 504 | return tensors.dtype; | |
| 505 | 505 | case IEnumerable<Tensor> tensors: | |
| 506 | - return tensors.First().dtype; | ||
| 506 | + return tensors.Where(x => x is not null).First().dtype; | ||
| 507 | 507 | case RefVariable variable: | |
| 508 | 508 | return variable.dtype; | |
| 509 | 509 | case ResourceVariable variable: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,7 @@ public Tensor[] TFE_TapeGradient(ITape tape, | |||
| 65 | 65 | { | |
| 66 | 66 | outgrad_vec = output_gradients.ToList(); | |
| 67 | 67 | } | |
| 68 | - var result = tape.ComputeGradient(target_vec, sources_vec, source_tensors_that_are_targets, outgrad_vec, false); | ||
| 68 | + var result = tape.ComputeGradient(target_vec, sources_vec, source_tensors_that_are_targets, outgrad_vec, true); | ||
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | 71 | bool unconnected_gradients_zero = unconnected_gradients == "zero"; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,11 @@ public override string ToString() | |||
| 10 | 10 | var str = NDArrayRender.ToString(nd); | |
| 11 | 11 | return $"tf.Tensor: shape={shape}, dtype={dtype.as_numpy_name()}, numpy={str}"; | |
| 12 | 12 | } | |
| 13 | - | ||
| 13 | + public string ToString(int maxLength) | ||
| 14 | + { | ||
| 15 | + var nd = new NDArray(this); | ||
| 16 | + var str = NDArrayRender.ToString(nd, maxLength); | ||
| 17 | + return $"tf.Tensor: shape={shape}, dtype={dtype.as_numpy_name()}, numpy={str}"; | ||
| 18 | + } | ||
| 14 | 19 | } | |
| 15 | 20 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,7 @@ public class LSTMCellArgs : AutoSerializeLayerArgs | |||
| 29 | 29 | [JsonProperty("unit_forget_bias")] | |
| 30 | 30 | public bool UnitForgetBias { get; set; } = true; | |
| 31 | 31 | [JsonProperty("implementation")] | |
| 32 | - public int Implementation { get; set; } = 1; | ||
| 32 | + public int Implementation { get; set; } = 2; | ||
| 33 | 33 | ||
| 34 | 34 | } | |
| 35 | 35 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -182,7 +182,7 @@ public ILayer LSTM(int units, | |||
| 182 | 182 | bool unit_forget_bias = true, | |
| 183 | 183 | float dropout = 0f, | |
| 184 | 184 | float recurrent_dropout = 0f, | |
| 185 | - int implementation = 1, | ||
| 185 | + int implementation = 2, | ||
| 186 | 186 | bool return_sequences = false, | |
| 187 | 187 | bool return_state = false, | |
| 188 | 188 | bool go_backwards = false, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,20 +7,20 @@ namespace Tensorflow.NumPy | |||
| 7 | 7 | { | |
| 8 | 8 | public class NDArrayRender | |
| 9 | 9 | { | |
| 10 | - public static string ToString(NDArray array) | ||
| 10 | + public static string ToString(NDArray array, int maxLength = 10) | ||
| 11 | 11 | { | |
| 12 | 12 | Shape shape = array.shape; | |
| 13 | 13 | if (shape.IsScalar) | |
| 14 | 14 | return Render(array); | |
| 15 | 15 | ||
| 16 | 16 | var s = new StringBuilder(); | |
| 17 | 17 | s.Append("array("); | |
| 18 | - Build(s, array); | ||
| 18 | + Build(s, array, maxLength); | ||
| 19 | 19 | s.Append(")"); | |
| 20 | 20 | return s.ToString(); | |
| 21 | 21 | } | |
| 22 | 22 | ||
| 23 | - static void Build(StringBuilder s, NDArray array) | ||
| 23 | + static void Build(StringBuilder s, NDArray array, int maxLength) | ||
| 24 | 24 | { | |
| 25 | 25 | var shape = array.shape; | |
| 26 | 26 | ||
@@ -35,11 +35,11 @@ static void Build(StringBuilder s, NDArray array) | |||
| 35 | 35 | var len = shape[0]; | |
| 36 | 36 | s.Append("["); | |
| 37 | 37 | ||
| 38 | - if (len <= 10) | ||
| 38 | + if (len <= maxLength) | ||
| 39 | 39 | { | |
| 40 | 40 | for (int i = 0; i < len; i++) | |
| 41 | 41 | { | |
| 42 | - Build(s, array[i]); | ||
| 42 | + Build(s, array[i], maxLength); | ||
| 43 | 43 | if (i < len - 1) | |
| 44 | 44 | { | |
| 45 | 45 | s.Append(", "); | |
@@ -49,9 +49,9 @@ static void Build(StringBuilder s, NDArray array) | |||
| 49 | 49 | } | |
| 50 | 50 | else | |
| 51 | 51 | { | |
| 52 | - for (int i = 0; i < 5; i++) | ||
| 52 | + for (int i = 0; i < maxLength / 2; i++) | ||
| 53 | 53 | { | |
| 54 | - Build(s, array[i]); | ||
| 54 | + Build(s, array[i], maxLength); | ||
| 55 | 55 | if (i < len - 1) | |
| 56 | 56 | { | |
| 57 | 57 | s.Append(", "); | |
@@ -62,9 +62,9 @@ static void Build(StringBuilder s, NDArray array) | |||
| 62 | 62 | s.Append(" ... "); | |
| 63 | 63 | s.AppendLine(); | |
| 64 | 64 | ||
| 65 | - for (int i = (int)len - 5; i < len; i++) | ||
| 65 | + for (int i = (int)len - maxLength / 2; i < len; i++) | ||
| 66 | 66 | { | |
| 67 | - Build(s, array[i]); | ||
| 67 | + Build(s, array[i], maxLength); | ||
| 68 | 68 | if (i < len - 1) | |
| 69 | 69 | { | |
| 70 | 70 | s.Append(", "); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,22 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Text; | ||
| 4 | + using Tensorflow.NumPy; | ||
| 5 | + | ||
| 6 | + namespace Tensorflow.Operations.Initializers | ||
| 7 | + { | ||
| 8 | + /// <summary> | ||
| 9 | + /// An initializer specially used for debugging (to load weights from disk). | ||
| 10 | + /// </summary> | ||
| 11 | + class NpyLoadInitializer : IInitializer | ||
| 12 | + { | ||
| 13 | + string _path; | ||
| 14 | + public NpyLoadInitializer(string path) { _path = path; } | ||
| 15 | + public string ClassName => ""; | ||
| 16 | + public IDictionary<string, object> Config => new Dictionary<string, object>(); | ||
| 17 | + public Tensor Apply(InitializerArgs args) | ||
| 18 | + { | ||
| 19 | + return np.load(_path); | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,7 +111,7 @@ https://tensorflownet.readthedocs.io</Description> | |||
| 111 | 111 | <PackageReference Include="MethodBoundaryAspect.Fody" Version="2.0.148" /> | |
| 112 | 112 | <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | |
| 113 | 113 | <PackageReference Include="OneOf" Version="3.0.223" /> | |
| 114 | - <PackageReference Include="Protobuf.Text" Version="0.7.0" /> | ||
| 114 | + <PackageReference Include="Protobuf.Text" Version="0.7.1" /> | ||
| 115 | 115 | <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" /> | |
| 116 | 116 | </ItemGroup> | |
| 117 | 117 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -179,8 +179,7 @@ protected virtual IVariableV1 _add_variable_with_custom_getter(VariableArgs args | |||
| 179 | 179 | // handles slot variables. | |
| 180 | 180 | if (!args.Overwrite || new_variable is RefVariable || new_variable is Trackable) | |
| 181 | 181 | { | |
| 182 | - var temp = new_variable as Trackable; | ||
| 183 | - var res = _track_trackable(temp, args.Name, args.Overwrite); | ||
| 182 | + var res = _track_trackable(new_variable as Trackable, args.Name, args.Overwrite); | ||
| 184 | 183 | Debug.Assert(res is IVariableV1); | |
| 185 | 184 | return res as IVariableV1; | |
| 186 | 185 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -793,7 +793,7 @@ public IRnnCell LSTMCell(int uints, | |||
| 793 | 793 | bool unit_forget_bias = true, | |
| 794 | 794 | float dropout = 0f, | |
| 795 | 795 | float recurrent_dropout = 0f, | |
| 796 | - int implementation = 1) | ||
| 796 | + int implementation = 2) | ||
| 797 | 797 | => new LSTMCell(new LSTMCellArgs | |
| 798 | 798 | { | |
| 799 | 799 | Units = uints, | |
@@ -846,7 +846,7 @@ public ILayer LSTM(int units, | |||
| 846 | 846 | bool unit_forget_bias = true, | |
| 847 | 847 | float dropout = 0f, | |
| 848 | 848 | float recurrent_dropout = 0f, | |
| 849 | - int implementation = 1, | ||
| 849 | + int implementation = 2, | ||
| 850 | 850 | bool return_sequences = false, | |
| 851 | 851 | bool return_state = false, | |
| 852 | 852 | bool go_backwards = false, | |
@@ -869,7 +869,8 @@ public ILayer LSTM(int units, | |||
| 869 | 869 | GoBackwards = go_backwards, | |
| 870 | 870 | Stateful = stateful, | |
| 871 | 871 | TimeMajor = time_major, | |
| 872 | - Unroll = unroll | ||
| 872 | + Unroll = unroll, | ||
| 873 | + UnitForgetBias = unit_forget_bias | ||
| 873 | 874 | }); | |
| 874 | 875 | ||
| 875 | 876 | /// <summary> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments