| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a7c9a75 commit a44028e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,7 +90,7 @@ public Tensor[] ComputeGradient(Tensor[] target_tensor_ids, | |||
| 90 | 90 | ||
| 91 | 91 | in_gradients = trace.backward_function(out_gradients.ToArray(), unneeded_gradients.ToArray()); | |
| 92 | 92 | ||
| 93 | - if (in_gradients.Count() != trace.input_tensor_id.Count()) | ||
| 93 | + if (in_gradients.Length != trace.input_tensor_id.Length && in_gradients.Length + unneeded_gradients.Count != trace.input_tensor_id.Length) | ||
| 94 | 94 | throw new RuntimeError($"Recorded operation '{trace.op_type}' returned too few gradients. Expected {trace.input_tensor_id.Length} but received {in_gradients.Count()}"); | |
| 95 | 95 | if (!_persistent) | |
| 96 | 96 | { | |
@@ -103,9 +103,11 @@ public Tensor[] ComputeGradient(Tensor[] target_tensor_ids, | |||
| 103 | 103 | in_gradients = new Tensor[trace.input_tensor_id.Length]; | |
| 104 | 104 | } | |
| 105 | 105 | ||
| 106 | - for (int i = 0; i < in_gradients.Length; ++i) | ||
| 106 | + bool skip_unneeded_id = trace.input_tensor_id.Length > in_gradients.Length; | ||
| 107 | + for (int i = 0, k = 0; i < in_gradients.Length && k < trace.input_tensor_id.Count(); ++i, ++k) | ||
| 107 | 108 | { | |
| 108 | - var id = trace.input_tensor_id[i]; | ||
| 109 | + if (skip_unneeded_id && unneeded_gradients.Contains(k)) ++k; | ||
| 110 | + var id = trace.input_tensor_id[k]; | ||
| 109 | 111 | if (in_gradients[i] != null) | |
| 110 | 112 | { | |
| 111 | 113 | var unaggregated_grads = gradients[id]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -639,6 +639,20 @@ public static Tensor[] _SqrtGrad(Operation op, Tensor[] grads) | |||
| 639 | 639 | }); | |
| 640 | 640 | } | |
| 641 | 641 | ||
| 642 | + [RegisterGradient("Rsqrt")] | ||
| 643 | + public static Tensor[] _RsqrtGrad(Operation op, Tensor[] grads) | ||
| 644 | + { | ||
| 645 | + var grad = grads[0]; | ||
| 646 | + var y = op.outputs[0]; | ||
| 647 | + | ||
| 648 | + return tf_with(ops.control_dependencies(grads), delegate | ||
| 649 | + { | ||
| 650 | + y = math_ops.conj(y); | ||
| 651 | + var factor = constant_op.constant(-0.5f, dtype: y.dtype); | ||
| 652 | + return new Tensor[] { grad * (factor * math_ops.square(y) * y) }; | ||
| 653 | + }); | ||
| 654 | + } | ||
| 655 | + | ||
| 642 | 656 | [RegisterGradient("Asin")] | |
| 643 | 657 | public static Tensor[] _ASinGrad(Operation op, Tensor[] grads) | |
| 644 | 658 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,6 +55,20 @@ public ILayer Conv2D(int filters, | |||
| 55 | 55 | IRegularizer bias_regularizer = null, | |
| 56 | 56 | IRegularizer activity_regularizer = null); | |
| 57 | 57 | ||
| 58 | + public ILayer Conv2DTranspose(int filters, | ||
| 59 | + Shape kernel_size = null, | ||
| 60 | + Shape strides = null, | ||
| 61 | + string output_padding = "valid", | ||
| 62 | + string data_format = null, | ||
| 63 | + Shape dilation_rate = null, | ||
| 64 | + string activation = null, | ||
| 65 | + bool use_bias = true, | ||
| 66 | + string kernel_initializer = null, | ||
| 67 | + string bias_initializer = null, | ||
| 68 | + string kernel_regularizer = null, | ||
| 69 | + string bias_regularizer = null, | ||
| 70 | + string activity_regularizer = null); | ||
| 71 | + | ||
| 58 | 72 | public ILayer Conv2D(int filters, | |
| 59 | 73 | Shape kernel_size = null, | |
| 60 | 74 | Shape strides = null, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments