| @@ -88,7 +88,7 @@ namespace Tensorflow.Keras.Engine | |||
| void ComputeTensorUsageCount() | |||
| { | |||
| var available_tensors = inputs.Select(x => x.GetHashCode()).ToList(); | |||
| var depth_keys = NodesByDepth.Keys.Reverse().Skip(1).ToArray(); | |||
| var depth_keys = NodesByDepth.Keys.OrderBy(x => x).Reverse().Skip(1).ToArray(); | |||
| foreach(var depth in depth_keys) | |||
| { | |||
| foreach(var node in NodesByDepth[depth]) | |||
| @@ -190,7 +190,7 @@ namespace Tensorflow.Keras.Engine | |||
| } | |||
| // Get sorted list of layer depths. | |||
| var depth_keys = layers_by_depth.Keys.Reverse(); | |||
| var depth_keys = layers_by_depth.Keys.OrderBy(x => x).Reverse(); | |||
| // Set self.layers ordered by depth. | |||
| var layers = new List<Layer>(); | |||
| @@ -200,12 +200,12 @@ namespace Tensorflow.Keras.Engine | |||
| // Network.layers needs to have a deterministic order: | |||
| // here we order them by traversal order. | |||
| layers_for_depth.Reverse(); | |||
| layers_for_depth = layers_for_depth.OrderBy(x => layer_indices[x]).ToList(); | |||
| layers.AddRange(layers_for_depth); | |||
| } | |||
| // Get sorted list of node depths. | |||
| depth_keys = nodes_by_depth.Keys.Reverse(); | |||
| depth_keys = nodes_by_depth.Keys.OrderBy(x => x).Reverse(); | |||
| return (network_nodes, nodes_by_depth, layers, layers_by_depth); | |||
| } | |||
| @@ -290,7 +290,7 @@ namespace Tensorflow.Keras.Engine | |||
| tensor_dict[x_id] = Enumerable.Range(0, tensor_usage_count[x_id]).Select(x => y1).ToArray(); | |||
| } | |||
| var depth_keys = NodesByDepth.Keys.Reverse().ToArray(); | |||
| var depth_keys = NodesByDepth.Keys.OrderBy(x => x).Reverse().ToArray(); | |||
| foreach(var depth in depth_keys) | |||
| { | |||
| @@ -2,6 +2,7 @@ | |||
| using System.Collections.Generic; | |||
| using System.Text; | |||
| using Tensorflow.Keras.ArgsDefinition; | |||
| using static Tensorflow.Binding; | |||
| namespace Tensorflow.Keras.Engine | |||
| { | |||
| @@ -25,7 +26,13 @@ namespace Tensorflow.Keras.Engine | |||
| protected override Tensors Call(Tensors inputs, Tensor state = null, bool is_training = false) | |||
| { | |||
| return base.Call(inputs, state, is_training); | |||
| return MakOp(inputs); | |||
| } | |||
| // [AutoGraph] | |||
| Tensors MakOp(Tensors inputs) | |||
| { | |||
| return inputs; | |||
| } | |||
| } | |||
| } | |||
| @@ -835,22 +835,24 @@ namespace Tensorflow | |||
| } | |||
| // Restore shape information where possible. | |||
| var paddings_constant = tensor_util.constant_value( | |||
| result.op.inputs[1], partial: true); | |||
| var input_shape = result.op.inputs[0].TensorShape; | |||
| if (input_shape.ndim > -1 && | |||
| !result.TensorShape.is_fully_defined() && | |||
| !(paddings_constant is null)) | |||
| if (!tf.Context.executing_eagerly()) | |||
| { | |||
| var new_shape = new List<int>(); | |||
| foreach((NDArray padding, int dim) in zip(paddings_constant.GetNDArrays(), np.array(input_shape.dims).GetNDArrays())) | |||
| var paddings_constant = tensor_util.constant_value(result.op.inputs[1], partial: true); | |||
| var input_shape = result.op.inputs[0].TensorShape; | |||
| if (input_shape.ndim > -1 && | |||
| !result.TensorShape.is_fully_defined() && | |||
| !(paddings_constant is null)) | |||
| { | |||
| if (padding is null || dim == -1 || padding.GetData<int>().Contains(-1)) | |||
| new_shape.Add(-1); | |||
| else | |||
| new_shape.Add(np.sum(padding) + dim); | |||
| var new_shape = new List<int>(); | |||
| foreach ((NDArray padding, int dim) in zip(paddings_constant.GetNDArrays(), np.array(input_shape.dims).GetNDArrays())) | |||
| { | |||
| if (padding is null || dim == -1 || padding.GetData<int>().Contains(-1)) | |||
| new_shape.Add(-1); | |||
| else | |||
| new_shape.Add(np.sum(padding) + dim); | |||
| } | |||
| result.set_shape(new_shape.ToArray()); | |||
| } | |||
| result.set_shape(new_shape.ToArray()); | |||
| } | |||
| return result; | |||
| @@ -175,6 +175,15 @@ namespace Tensorflow | |||
| public static Tensor pad(Tensor input, Tensor paddings, string name = null) | |||
| { | |||
| if (tf.Context.executing_eagerly()) | |||
| { | |||
| var results = tf.Runner.TFE_FastPathExecute(tf.Context, tf.Context.DeviceName, | |||
| "Pad", name, | |||
| null, | |||
| input, paddings); | |||
| return results[0]; | |||
| } | |||
| var _op = tf.OpDefLib._apply_op_helper("Pad", name: name, args: new { input, paddings }); | |||
| return _op.output; | |||