| @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowBenchmark", "src\ | |||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowHub", "src\TensorFlowHub\TensorFlowHub.csproj", "{8FD59A5A-97EB-457E-B9F1-D88B0C822C6E}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowHub", "src\TensorFlowHub\TensorFlowHub.csproj", "{8FD59A5A-97EB-457E-B9F1-D88B0C822C6E}" | ||||
| EndProject | EndProject | ||||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TensorFlowText", "src\TensorFlowText\TensorFlowText.csproj", "{B598E5D5-BD2D-4191-8532-F2FBAC31AB81}" | |||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowText", "src\TensorFlowText\TensorFlowText.csproj", "{B598E5D5-BD2D-4191-8532-F2FBAC31AB81}" | |||||
| EndProject | |||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{F219B9B9-B873-4342-BF85-7E89E7F5D64F}" | |||||
| EndProject | EndProject | ||||
| Global | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| @@ -57,6 +59,10 @@ Global | |||||
| {B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Debug|Any CPU.Build.0 = Debug|Any CPU | {B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| {B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Release|Any CPU.ActiveCfg = Release|Any CPU | {B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| {B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Release|Any CPU.Build.0 = Release|Any CPU | {B598E5D5-BD2D-4191-8532-F2FBAC31AB81}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| {F219B9B9-B873-4342-BF85-7E89E7F5D64F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
| {F219B9B9-B873-4342-BF85-7E89E7F5D64F}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
| {F219B9B9-B873-4342-BF85-7E89E7F5D64F}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
| {F219B9B9-B873-4342-BF85-7E89E7F5D64F}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
| EndGlobalSection | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
| @@ -41,7 +41,7 @@ namespace Keras.Layers | |||||
| Console.WriteLine("Building Layer \"" + name + "\" ..."); | Console.WriteLine("Building Layer \"" + name + "\" ..."); | ||||
| if (stddev == -1) | if (stddev == -1) | ||||
| stddev = (float)(1 / Math.Sqrt(2)); | stddev = (float)(1 / Math.Sqrt(2)); | ||||
| var dim = input_shape.Dimensions; | |||||
| var dim = input_shape.dims; | |||||
| var input_dim = dim[dim.Length - 1]; | var input_dim = dim[dim.Length - 1]; | ||||
| W = tf.Variable(create_tensor(new int[] { input_dim, units }, seed: seed, stddev: (float)stddev)); | W = tf.Variable(create_tensor(new int[] { input_dim, units }, seed: seed, stddev: (float)stddev)); | ||||
| WShape = new TensorShape(W.shape); | WShape = new TensorShape(W.shape); | ||||
| @@ -52,7 +52,7 @@ namespace Keras.Layers | |||||
| var dot = tf.matmul(x, W); | var dot = tf.matmul(x, W); | ||||
| if (this.activation != null) | if (this.activation != null) | ||||
| dot = activation.Activate(dot); | dot = activation.Activate(dot); | ||||
| Console.WriteLine("Calling Layer \"" + name + "(" + np.array(dot.TensorShape.Dimensions).ToString() + ")\" ..."); | |||||
| Console.WriteLine("Calling Layer \"" + name + "(" + np.array(dot.TensorShape.dims).ToString() + ")\" ..."); | |||||
| return dot; | return dot; | ||||
| } | } | ||||
| public TensorShape __shape__() | public TensorShape __shape__() | ||||
| @@ -61,7 +61,7 @@ namespace Keras.Layers | |||||
| } | } | ||||
| public TensorShape output_shape(TensorShape input_shape) | public TensorShape output_shape(TensorShape input_shape) | ||||
| { | { | ||||
| var output_shape = input_shape.Dimensions; | |||||
| var output_shape = input_shape.dims; | |||||
| output_shape[output_shape.Length - 1] = units; | output_shape[output_shape.Length - 1] = units; | ||||
| return new TensorShape(output_shape); | return new TensorShape(output_shape); | ||||
| } | } | ||||
| @@ -11,13 +11,13 @@ namespace Tensorflow.Contrib.Learn.Estimators | |||||
| bool _shape_is_compatible_0dim(Shape _this, Shape _other) | bool _shape_is_compatible_0dim(Shape _this, Shape _other) | ||||
| { | { | ||||
| var __other = tensor_shape.as_shape(_other); | var __other = tensor_shape.as_shape(_other); | ||||
| if (_this.Dimensions == null || __other.Dimensions == null) | |||||
| if (_this.Dimensions == null || __other.dims == null) | |||||
| return true; | return true; | ||||
| if (_this.NDim != __other.NDim) | |||||
| if (_this.NDim != __other.ndim) | |||||
| return false; | return false; | ||||
| foreach (var (x_dim, y_dim) in _this.Dimensions.Zip(__other.Dimensions, (x_dim, y_dim) => (x_dim, y_dim))) | |||||
| foreach (var (x_dim, y_dim) in _this.Dimensions.Zip(__other.dims, (x_dim, y_dim) => (x_dim, y_dim))) | |||||
| { | { | ||||
| if (x_dim != y_dim) | if (x_dim != y_dim) | ||||
| return false; | return false; | ||||
| @@ -25,10 +25,6 @@ namespace Tensorflow.Framework | |||||
| } | } | ||||
| public static TensorShape as_shape(this Shape shape) | public static TensorShape as_shape(this Shape shape) | ||||
| { | |||||
| if (shape is TensorShape tshape) | |||||
| return tshape; | |||||
| return new TensorShape(shape); | |||||
| } | |||||
| => new TensorShape(shape.Dimensions); | |||||
| } | } | ||||
| } | } | ||||
| @@ -81,7 +81,7 @@ namespace Tensorflow.Keras.Layers | |||||
| protected override void build(TensorShape input_shape) | protected override void build(TensorShape input_shape) | ||||
| { | { | ||||
| var ndims = input_shape.NDim; | |||||
| var ndims = input_shape.ndim; | |||||
| foreach (var (idx, x) in Python.enumerate(axis)) | foreach (var (idx, x) in Python.enumerate(axis)) | ||||
| if (x < 0) | if (x < 0) | ||||
| axis[idx] = ndims + x; | axis[idx] = ndims + x; | ||||
| @@ -91,7 +91,7 @@ namespace Tensorflow.Keras.Layers | |||||
| _data_format = "NHWC"; | _data_format = "NHWC"; | ||||
| var param_dtype = _dtype == TF_DataType.DtInvalid ? TF_DataType.TF_FLOAT : _dtype; | var param_dtype = _dtype == TF_DataType.DtInvalid ? TF_DataType.TF_FLOAT : _dtype; | ||||
| var param_shape = new int[] { input_shape.Dimensions[axis[0]] }; | |||||
| var param_shape = new int[] { input_shape.dims[axis[0]] }; | |||||
| if (scale) | if (scale) | ||||
| gamma = add_weight("gamma", | gamma = add_weight("gamma", | ||||
| @@ -72,8 +72,8 @@ namespace Tensorflow.Keras.Layers | |||||
| { | { | ||||
| int channel_axis = data_format == "channels_first" ? 1 : -1; | int channel_axis = data_format == "channels_first" ? 1 : -1; | ||||
| int input_dim = channel_axis < 0 ? | int input_dim = channel_axis < 0 ? | ||||
| input_shape.Dimensions[input_shape.NDim + channel_axis] : | |||||
| input_shape.Dimensions[channel_axis]; | |||||
| input_shape.dims[input_shape.ndim + channel_axis] : | |||||
| input_shape.dims[channel_axis]; | |||||
| var kernel_shape = new int[] { kernel_size[0], kernel_size[1], input_dim, filters }; | var kernel_shape = new int[] { kernel_size[0], kernel_size[1], input_dim, filters }; | ||||
| kernel = add_weight(name: "kernel", | kernel = add_weight(name: "kernel", | ||||
| shape: kernel_shape, | shape: kernel_shape, | ||||
| @@ -51,7 +51,7 @@ namespace Tensorflow.Keras.Layers | |||||
| protected override void build(TensorShape input_shape) | protected override void build(TensorShape input_shape) | ||||
| { | { | ||||
| var last_dim = input_shape.Dimensions.Last(); | |||||
| var last_dim = input_shape.dims.Last(); | |||||
| var axes = new Dictionary<int, int>(); | var axes = new Dictionary<int, int>(); | ||||
| axes[-1] = last_dim; | axes[-1] = last_dim; | ||||
| input_spec = new InputSpec(min_ndim: 2, axes: axes); | input_spec = new InputSpec(min_ndim: 2, axes: axes); | ||||
| @@ -30,7 +30,7 @@ namespace Tensorflow.Operations.Initializers | |||||
| if (dtype == TF_DataType.DtInvalid) | if (dtype == TF_DataType.DtInvalid) | ||||
| dtype = this.dtype; | dtype = this.dtype; | ||||
| return array_ops.ones(shape.Dimensions, dtype); | |||||
| return array_ops.ones(shape.dims, dtype); | |||||
| } | } | ||||
| public object get_config() | public object get_config() | ||||
| @@ -132,9 +132,9 @@ namespace Tensorflow | |||||
| if(weights > 0) | if(weights > 0) | ||||
| { | { | ||||
| var weights_tensor = ops.convert_to_tensor(weights); | var weights_tensor = ops.convert_to_tensor(weights); | ||||
| var labels_rank = labels.TensorShape.NDim; | |||||
| var labels_rank = labels.TensorShape.ndim; | |||||
| var weights_shape = weights_tensor.TensorShape; | var weights_shape = weights_tensor.TensorShape; | ||||
| var weights_rank = weights_shape.NDim; | |||||
| var weights_rank = weights_shape.ndim; | |||||
| if (labels_rank > -1 && weights_rank > -1) | if (labels_rank > -1 && weights_rank > -1) | ||||
| { | { | ||||
| @@ -35,18 +35,18 @@ namespace Tensorflow.Operations | |||||
| string name = null, | string name = null, | ||||
| string data_format = null) | string data_format = null) | ||||
| { | { | ||||
| var num_total_dims = filter_shape.NDim; | |||||
| var num_total_dims = filter_shape.ndim; | |||||
| var num_spatial_dims = num_total_dims - 2; | var num_spatial_dims = num_total_dims - 2; | ||||
| int input_channels_dim; | int input_channels_dim; | ||||
| int[] spatial_dims; | int[] spatial_dims; | ||||
| if (string.IsNullOrEmpty(data_format) || !data_format.StartsWith("NC")) | if (string.IsNullOrEmpty(data_format) || !data_format.StartsWith("NC")) | ||||
| { | { | ||||
| input_channels_dim = input_shape.Dimensions[num_spatial_dims + 1]; | |||||
| input_channels_dim = input_shape.dims[num_spatial_dims + 1]; | |||||
| spatial_dims = Enumerable.Range(1, num_spatial_dims).ToArray(); | spatial_dims = Enumerable.Range(1, num_spatial_dims).ToArray(); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| input_channels_dim = input_shape.Dimensions[1]; | |||||
| input_channels_dim = input_shape.dims[1]; | |||||
| spatial_dims = Enumerable.Range(2, num_spatial_dims).ToArray(); | spatial_dims = Enumerable.Range(2, num_spatial_dims).ToArray(); | ||||
| } | } | ||||
| @@ -36,7 +36,7 @@ namespace Tensorflow.Operations | |||||
| { | { | ||||
| this.padding = padding; | this.padding = padding; | ||||
| this.name = name; | this.name = name; | ||||
| var conv_dims = input_shape.NDim - 2; | |||||
| var conv_dims = input_shape.ndim - 2; | |||||
| if (conv_dims == 1) | if (conv_dims == 1) | ||||
| { | { | ||||
| throw new NotImplementedException("_NonAtrousConvolution conv_dims 1"); | throw new NotImplementedException("_NonAtrousConvolution conv_dims 1"); | ||||
| @@ -33,7 +33,7 @@ namespace Tensorflow.Operations | |||||
| { | { | ||||
| var dilation_rate_tensor = ops.convert_to_tensor(dilation_rate, TF_DataType.TF_INT32, name: "dilation_rate"); | var dilation_rate_tensor = ops.convert_to_tensor(dilation_rate, TF_DataType.TF_INT32, name: "dilation_rate"); | ||||
| var rate_shape = dilation_rate_tensor.TensorShape; | var rate_shape = dilation_rate_tensor.TensorShape; | ||||
| var num_spatial_dims = rate_shape.Dimensions[0]; | |||||
| var num_spatial_dims = rate_shape.dims[0]; | |||||
| int starting_spatial_dim = -1; | int starting_spatial_dim = -1; | ||||
| if (!string.IsNullOrEmpty(data_format) && data_format.StartsWith("NC")) | if (!string.IsNullOrEmpty(data_format) && data_format.StartsWith("NC")) | ||||
| starting_spatial_dim = 2; | starting_spatial_dim = 2; | ||||
| @@ -19,6 +19,7 @@ using System.Collections.Generic; | |||||
| using System.Linq; | using System.Linq; | ||||
| using static Tensorflow.Python; | using static Tensorflow.Python; | ||||
| using Tensorflow.Util; | using Tensorflow.Util; | ||||
| using NumSharp; | |||||
| namespace Tensorflow.Operations | namespace Tensorflow.Operations | ||||
| { | { | ||||
| @@ -94,12 +95,12 @@ namespace Tensorflow.Operations | |||||
| var batch_size = _best_effort_input_batch_size(flat_input); | var batch_size = _best_effort_input_batch_size(flat_input); | ||||
| var inputs_got_shape = flat_input.Select(input_ => input_.TensorShape.with_rank_at_least(3)).ToArray(); | var inputs_got_shape = flat_input.Select(input_ => input_.TensorShape.with_rank_at_least(3)).ToArray(); | ||||
| var dims = inputs_got_shape[0].Dimensions.Take(2).ToArray(); | |||||
| var dims = inputs_got_shape[0].dims.Take(2).ToArray(); | |||||
| var (const_time_steps, const_batch_size) = (dims[0], dims[1]); | var (const_time_steps, const_batch_size) = (dims[0], dims[1]); | ||||
| foreach(var shape in inputs_got_shape) | foreach(var shape in inputs_got_shape) | ||||
| { | { | ||||
| if (shape[2] == -1) | |||||
| if (shape.dims[2] == -1) | |||||
| throw new ValueError("Input size (depth of inputs) must be accessible via shape inference," + | throw new ValueError("Input size (depth of inputs) must be accessible via shape inference," + | ||||
| " but saw value None."); | " but saw value None."); | ||||
| @@ -190,7 +191,7 @@ namespace Tensorflow.Operations | |||||
| public static Tensor _transpose_batch_time(Tensor x) | public static Tensor _transpose_batch_time(Tensor x) | ||||
| { | { | ||||
| var x_static_shape = x.TensorShape; | var x_static_shape = x.TensorShape; | ||||
| if (x_static_shape.NDim == 1) | |||||
| if (x_static_shape.ndim == 1) | |||||
| return x; | return x; | ||||
| var x_rank = array_ops.rank(x); | var x_rank = array_ops.rank(x); | ||||
| @@ -201,9 +202,9 @@ namespace Tensorflow.Operations | |||||
| }; | }; | ||||
| var x_t = array_ops.transpose(x, array_ops.concat(con1, 0)); | var x_t = array_ops.transpose(x, array_ops.concat(con1, 0)); | ||||
| var dims = new int[] { x_static_shape.Dimensions[1], x_static_shape.Dimensions[0] } | |||||
| var dims = new int[] { x_static_shape.dims[1], x_static_shape.dims[0] } | |||||
| .ToList(); | .ToList(); | ||||
| dims.AddRange(x_static_shape.Dimensions.Skip(2)); | |||||
| dims.AddRange(x_static_shape.dims.Skip(2)); | |||||
| var shape = new TensorShape(dims.ToArray()); | var shape = new TensorShape(dims.ToArray()); | ||||
| x_t.SetShape(shape); | x_t.SetShape(shape); | ||||
| @@ -221,12 +222,12 @@ namespace Tensorflow.Operations | |||||
| foreach(var input_ in flat_input) | foreach(var input_ in flat_input) | ||||
| { | { | ||||
| var shape = input_.TensorShape; | var shape = input_.TensorShape; | ||||
| if (shape.NDim < 0) | |||||
| if (shape.ndim < 0) | |||||
| continue; | continue; | ||||
| if (shape.NDim < 2) | |||||
| if (shape.ndim < 2) | |||||
| throw new ValueError($"Expected input tensor {input_.name} to have rank at least 2"); | throw new ValueError($"Expected input tensor {input_.name} to have rank at least 2"); | ||||
| var batch_size = shape.Dimensions[1]; | |||||
| var batch_size = shape.dims[1]; | |||||
| if (batch_size > -1) | if (batch_size > -1) | ||||
| throw new ValueError("_best_effort_input_batch_size batch_size > -1"); | throw new ValueError("_best_effort_input_batch_size batch_size > -1"); | ||||
| //return batch_size; | //return batch_size; | ||||
| @@ -33,11 +33,11 @@ namespace Tensorflow.Operations | |||||
| throw new ValueError($"prefix tensor must be either a scalar or vector, but saw tensor: {p}"); | throw new ValueError($"prefix tensor must be either a scalar or vector, but saw tensor: {p}"); | ||||
| var s_tensor_shape = new TensorShape(suffix); | var s_tensor_shape = new TensorShape(suffix); | ||||
| var s_static = s_tensor_shape.NDim > -1 ? | |||||
| s_tensor_shape.Dimensions : | |||||
| var s_static = s_tensor_shape.ndim > -1 ? | |||||
| s_tensor_shape.dims : | |||||
| null; | null; | ||||
| var s = s_tensor_shape.is_fully_defined() ? | var s = s_tensor_shape.is_fully_defined() ? | ||||
| constant_op.constant(s_tensor_shape.Dimensions, dtype: dtypes.int32) : | |||||
| constant_op.constant(s_tensor_shape.dims, dtype: dtypes.int32) : | |||||
| null; | null; | ||||
| if (@static) | if (@static) | ||||
| @@ -40,7 +40,7 @@ namespace Tensorflow | |||||
| verify_shape: verify_shape, | verify_shape: verify_shape, | ||||
| allow_broadcast: false); | allow_broadcast: false); | ||||
| public static Tensor zeros(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) | |||||
| public static Tensor zeros(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) | |||||
| { | { | ||||
| dtype = dtype.as_base_dtype(); | dtype = dtype.as_base_dtype(); | ||||
| return with(ops.name_scope(name, "zeros", shape), scope => | return with(ops.name_scope(name, "zeros", shape), scope => | ||||
| @@ -92,16 +92,16 @@ namespace Tensorflow | |||||
| return shape < 1000; | return shape < 1000; | ||||
| } | } | ||||
| private static Tensor _constant_if_small<T>(T value, Shape shape, TF_DataType dtype, string name) | |||||
| private static Tensor _constant_if_small<T>(T value, TensorShape shape, TF_DataType dtype, string name) | |||||
| { | { | ||||
| Tensor tShape = null; | Tensor tShape = null; | ||||
| if (shape.Size < 1000) | |||||
| if (shape.size < 1000) | |||||
| { | { | ||||
| return constant_op.constant(value, shape: shape, dtype: dtype, name: name); | return constant_op.constant(value, shape: shape, dtype: dtype, name: name); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| tShape = constant_op._tensor_shape_tensor_conversion_function(shape.as_shape()); | |||||
| tShape = constant_op._tensor_shape_tensor_conversion_function(shape); | |||||
| var c = constant_op.constant(0, dtype: dtype); | var c = constant_op.constant(0, dtype: dtype); | ||||
| return gen_array_ops.fill(tShape, c, name: name); | return gen_array_ops.fill(tShape, c, name: name); | ||||
| } | } | ||||
| @@ -194,8 +194,8 @@ namespace Tensorflow | |||||
| name = scope; | name = scope; | ||||
| var input_tensor = ops.convert_to_tensor(input); | var input_tensor = ops.convert_to_tensor(input); | ||||
| var input_shape = tensor_util.to_shape(input_tensor.shape); | var input_shape = tensor_util.to_shape(input_tensor.shape); | ||||
| if (optimize && input_shape.NDim > 0) | |||||
| return constant_op.constant(input_shape.NDim, dtype: tf.int32, name: name); | |||||
| if (optimize && input_shape.ndim > 0) | |||||
| return constant_op.constant(input_shape.ndim, dtype: tf.int32, name: name); | |||||
| else | else | ||||
| return gen_array_ops.rank(input, name); | return gen_array_ops.rank(input, name); | ||||
| }); | }); | ||||
| @@ -372,7 +372,7 @@ namespace Tensorflow | |||||
| { | { | ||||
| if (input_shape.is_fully_defined()) | if (input_shape.is_fully_defined()) | ||||
| { | { | ||||
| return constant_op.constant(input_shape.Size, dtype: out_type, name: name); | |||||
| return constant_op.constant(input_shape.size, dtype: out_type, name: name); | |||||
| } | } | ||||
| } | } | ||||
| @@ -39,9 +39,9 @@ namespace Tensorflow | |||||
| predictions = ops.convert_to_tensor(predictions); | predictions = ops.convert_to_tensor(predictions); | ||||
| labels = ops.convert_to_tensor(labels); | labels = ops.convert_to_tensor(labels); | ||||
| var predictions_shape = predictions.TensorShape; | var predictions_shape = predictions.TensorShape; | ||||
| var predictions_rank = predictions_shape.NDim; | |||||
| var predictions_rank = predictions_shape.ndim; | |||||
| var labels_shape = labels.TensorShape; | var labels_shape = labels.TensorShape; | ||||
| var labels_rank = labels_shape.NDim; | |||||
| var labels_rank = labels_shape.ndim; | |||||
| if(labels_rank > -1 && predictions_rank > -1) | if(labels_rank > -1 && predictions_rank > -1) | ||||
| { | { | ||||
| // Use static rank. | // Use static rank. | ||||
| @@ -81,7 +81,7 @@ namespace Tensorflow | |||||
| rate = ops.convert_to_tensor(rate, dtype: x.dtype, name: "rate"); | rate = ops.convert_to_tensor(rate, dtype: x.dtype, name: "rate"); | ||||
| // Do nothing if we know rate == 0 | // Do nothing if we know rate == 0 | ||||
| var val = tensor_util.constant_value(rate); | var val = tensor_util.constant_value(rate); | ||||
| if (!(val is null) && val.Data<float>(0) == 0) | |||||
| if (!(val is null) && val.Data<float>()[0] == 0) | |||||
| return x; | return x; | ||||
| noise_shape = _get_noise_shape(x, noise_shape); | noise_shape = _get_noise_shape(x, noise_shape); | ||||
| @@ -185,7 +185,7 @@ namespace Tensorflow | |||||
| logits.get_shape()[:-1].is_fully_defined());*/ | logits.get_shape()[:-1].is_fully_defined());*/ | ||||
| // Check if no reshapes are required. | // Check if no reshapes are required. | ||||
| if(logits.TensorShape.NDim == 2) | |||||
| if(logits.TensorShape.ndim == 2) | |||||
| { | { | ||||
| var (cost, _) = gen_nn_ops.sparse_softmax_cross_entropy_with_logits( | var (cost, _) = gen_nn_ops.sparse_softmax_cross_entropy_with_logits( | ||||
| precise_logits, labels, name: name); | precise_logits, labels, name: name); | ||||
| @@ -257,11 +257,11 @@ namespace Tensorflow | |||||
| // Set output shape if known. | // Set output shape if known. | ||||
| // if not context.executing_eagerly(): | // if not context.executing_eagerly(): | ||||
| var shape = logits.TensorShape; | var shape = logits.TensorShape; | ||||
| if(shape != null && shape.NDim > 0) | |||||
| if(shape != null && shape.ndim > 0) | |||||
| { | { | ||||
| var product = 1; | var product = 1; | ||||
| var product_valid = true; | var product_valid = true; | ||||
| foreach(var d in shape.Dimensions.Take(shape.NDim - 1)) | |||||
| foreach(var d in shape.dims.Take(shape.ndim - 1)) | |||||
| { | { | ||||
| if(d == -1) | if(d == -1) | ||||
| { | { | ||||
| @@ -15,6 +15,7 @@ | |||||
| ******************************************************************************/ | ******************************************************************************/ | ||||
| using NumSharp; | using NumSharp; | ||||
| using NumSharp.Backends; | |||||
| using System; | using System; | ||||
| using System.Collections; | using System.Collections; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| @@ -48,7 +49,7 @@ namespace Tensorflow | |||||
| case ICollection arr: | case ICollection arr: | ||||
| return arr.Count; | return arr.Count; | ||||
| case NDArray ndArray: | case NDArray ndArray: | ||||
| return ndArray.len; | |||||
| return ndArray.shape[0]; | |||||
| case IEnumerable enumerable: | case IEnumerable enumerable: | ||||
| return enumerable.OfType<object>().Count(); | return enumerable.OfType<object>().Count(); | ||||
| } | } | ||||
| @@ -141,9 +142,12 @@ namespace Tensorflow | |||||
| } | } | ||||
| public static IEnumerable<(T, T)> zip<T>(NDArray t1, NDArray t2) | public static IEnumerable<(T, T)> zip<T>(NDArray t1, NDArray t2) | ||||
| where T : unmanaged | |||||
| { | { | ||||
| for (int i = 0; i < t1.size; i++) | |||||
| yield return (t1.Data<T>(i), t2.Data<T>(i)); | |||||
| var a = t1.AsIterator<T>(); | |||||
| var b = t2.AsIterator<T>(); | |||||
| while (a.HasNext()) | |||||
| yield return (a.MoveNext(), b.MoveNext()); | |||||
| } | } | ||||
| public static IEnumerable<(T1, T2)> zip<T1, T2>(IList<T1> t1, IList<T2> t2) | public static IEnumerable<(T1, T2)> zip<T1, T2>(IList<T1> t1, IList<T2> t2) | ||||
| @@ -152,10 +156,14 @@ namespace Tensorflow | |||||
| yield return (t1[i], t2[i]); | yield return (t1[i], t2[i]); | ||||
| } | } | ||||
| public static IEnumerable<(T1, T2)> zip<T1, T2>(NDArray t1, NDArray t2) | |||||
| public static IEnumerable<(T1, T2)> zip<T1, T2>(NDArray t1, NDArray t2) | |||||
| where T1: unmanaged | |||||
| where T2: unmanaged | |||||
| { | { | ||||
| for (int i = 0; i < t1.size; i++) | |||||
| yield return (t1.Data<T1>(i), t2.Data<T2>(i)); | |||||
| var a = t1.AsIterator<T1>(); | |||||
| var b = t2.AsIterator<T2>(); | |||||
| while(a.HasNext()) | |||||
| yield return (a.MoveNext(), b.MoveNext()); | |||||
| } | } | ||||
| public static IEnumerable<(T1, T2)> zip<T1, T2>(IEnumerable<T1> e1, IEnumerable<T2> e2) | public static IEnumerable<(T1, T2)> zip<T1, T2>(IEnumerable<T1> e1, IEnumerable<T2> e2) | ||||
| @@ -100,19 +100,19 @@ namespace Tensorflow | |||||
| switch (value.dtype.Name) | switch (value.dtype.Name) | ||||
| { | { | ||||
| case "Int32": | case "Int32": | ||||
| full_values.Add(value.Data<int>(0)); | |||||
| full_values.Add(value.Data<int>()[0]); | |||||
| break; | break; | ||||
| case "Int64": | case "Int64": | ||||
| full_values.Add(value.Data<long>(0)); | |||||
| full_values.Add(value.Data<long>()[0]); | |||||
| break; | break; | ||||
| case "Single": | case "Single": | ||||
| full_values.Add(value.Data<float>(0)); | |||||
| full_values.Add(value.Data<float>()[0]); | |||||
| break; | break; | ||||
| case "Double": | case "Double": | ||||
| full_values.Add(value.Data<double>(0)); | |||||
| full_values.Add(value.Data<double>()[0]); | |||||
| break; | break; | ||||
| case "String": | case "String": | ||||
| full_values.Add(value.Data<string>(0)); | |||||
| full_values.Add(value.Data<string>()[0]); | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| @@ -30,7 +30,7 @@ Docs: https://tensorflownet.readthedocs.io</Description> | |||||
| 8. Upgrade NumSharp. | 8. Upgrade NumSharp. | ||||
| 9. Fix strided_slice_grad type convention error. | 9. Fix strided_slice_grad type convention error. | ||||
| 10. Add AbsGrad.</PackageReleaseNotes> | 10. Add AbsGrad.</PackageReleaseNotes> | ||||
| <LangVersion>7.2</LangVersion> | |||||
| <LangVersion>7.3</LangVersion> | |||||
| <FileVersion>0.10.3.0</FileVersion> | <FileVersion>0.10.3.0</FileVersion> | ||||
| <PackageLicenseFile>LICENSE</PackageLicenseFile> | <PackageLicenseFile>LICENSE</PackageLicenseFile> | ||||
| <PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | <PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||||
| @@ -63,11 +63,14 @@ Docs: https://tensorflownet.readthedocs.io</Description> | |||||
| <ItemGroup> | <ItemGroup> | ||||
| <PackageReference Include="Google.Protobuf" Version="3.9.0" /> | <PackageReference Include="Google.Protobuf" Version="3.9.0" /> | ||||
| <PackageReference Include="NumSharp" Version="0.10.6" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <Folder Include="Distribute\" /> | <Folder Include="Distribute\" /> | ||||
| <Folder Include="Keras\Initializers\" /> | <Folder Include="Keras\Initializers\" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | |||||
| <ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" /> | |||||
| </ItemGroup> | |||||
| </Project> | </Project> | ||||
| @@ -513,7 +513,7 @@ namespace Tensorflow | |||||
| Marshal.Copy(nd1.Data<byte>(), 0, dotHandle, nd.size); | Marshal.Copy(nd1.Data<byte>(), 0, dotHandle, nd.size); | ||||
| break; | break; | ||||
| case "String": | case "String": | ||||
| return new Tensor(UTF8Encoding.UTF8.GetBytes(nd.Data<string>(0)), TF_DataType.TF_STRING); | |||||
| return new Tensor(UTF8Encoding.UTF8.GetBytes(nd.Data<string>()[0]), TF_DataType.TF_STRING); | |||||
| default: | default: | ||||
| throw new NotImplementedException($"Marshal.Copy failed for {nd.dtype.Name}."); | throw new NotImplementedException($"Marshal.Copy failed for {nd.dtype.Name}."); | ||||
| } | } | ||||
| @@ -77,12 +77,12 @@ namespace Tensorflow | |||||
| throw new ArgumentNullException(nameof(tensor)); | throw new ArgumentNullException(nameof(tensor)); | ||||
| } | } | ||||
| if (tensor.TensorShape.NDim != 0) | |||||
| if (tensor.TensorShape.ndim != 0) | |||||
| { | { | ||||
| throw new ArgumentException("Tensor must have 0 dimensions in order to convert to scalar"); | throw new ArgumentException("Tensor must have 0 dimensions in order to convert to scalar"); | ||||
| } | } | ||||
| if (tensor.TensorShape.Size != 1) | |||||
| if (tensor.TensorShape.size != 1) | |||||
| { | { | ||||
| throw new ArgumentException("Tensor must have size 1 in order to convert to scalar"); | throw new ArgumentException("Tensor must have size 1 in order to convert to scalar"); | ||||
| } | } | ||||
| @@ -105,9 +105,9 @@ namespace Tensorflow | |||||
| public TensorShape TensorShape => tensor_util.to_shape(shape); | public TensorShape TensorShape => tensor_util.to_shape(shape); | ||||
| public void SetShape(Shape shape) | |||||
| public void SetShape(TensorShape shape) | |||||
| { | { | ||||
| this.shape = shape.Dimensions; | |||||
| this.shape = shape.dims; | |||||
| } | } | ||||
| public void set_shape(Tensor shape) | public void set_shape(Tensor shape) | ||||
| @@ -7,27 +7,30 @@ namespace Tensorflow | |||||
| /// <summary> | /// <summary> | ||||
| /// Represents the shape of a `Tensor`. | /// Represents the shape of a `Tensor`. | ||||
| /// </summary> | /// </summary> | ||||
| public class TensorShape : Shape | |||||
| public class TensorShape | |||||
| { | { | ||||
| public int[] dims => Dimensions; | |||||
| private Shape shape; | |||||
| public int[] dims => shape.Dimensions; | |||||
| public int ndim => shape.NDim; | |||||
| public int size => shape.Size; | |||||
| public TensorShape(TensorShapeProto proto) | public TensorShape(TensorShapeProto proto) | ||||
| { | { | ||||
| if (proto.UnknownRank) return; | if (proto.UnknownRank) return; | ||||
| Reshape(proto.Dim.Select(x => (int)x.Size).ToArray()); | |||||
| shape.reshape(proto.Dim.Select(x => (int)x.Size).ToArray()); | |||||
| } | } | ||||
| public TensorShape(params int[] dims) : base(dims) | |||||
| public TensorShape(params int[] dims) | |||||
| { | { | ||||
| shape = new Shape(dims); | |||||
| } | } | ||||
| public TensorShape this[Slice slice] | public TensorShape this[Slice slice] | ||||
| { | { | ||||
| get | get | ||||
| { | { | ||||
| return new TensorShape(Dimensions.Skip(slice.Start.Value) | |||||
| return new TensorShape(dims.Skip(slice.Start.Value) | |||||
| .Take(slice.Length.Value) | .Take(slice.Length.Value) | ||||
| .ToArray()); | .ToArray()); | ||||
| } | } | ||||
| @@ -39,7 +42,7 @@ namespace Tensorflow | |||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public bool is_fully_defined() | public bool is_fully_defined() | ||||
| { | { | ||||
| return Dimensions != null && Dimensions.Count(x => x < 1) == 0; | |||||
| return dims != null && dims.Count(x => x < 1) == 0; | |||||
| } | } | ||||
| public bool is_compatible_with(TensorShape shape2) | public bool is_compatible_with(TensorShape shape2) | ||||
| @@ -49,7 +52,7 @@ namespace Tensorflow | |||||
| public TensorShape with_rank_at_least(int rank) | public TensorShape with_rank_at_least(int rank) | ||||
| { | { | ||||
| if (rank != this.NDim) | |||||
| if (rank != ndim) | |||||
| throw new ValueError($"Shape {this} must have rank at least {rank}"); | throw new ValueError($"Shape {this} must have rank at least {rank}"); | ||||
| else | else | ||||
| return this; | return this; | ||||
| @@ -64,13 +67,16 @@ namespace Tensorflow | |||||
| { | { | ||||
| var other = new TensorShape(other_); | var other = new TensorShape(other_); | ||||
| if (NDim < 0 || other.NDim < 0) | |||||
| if (ndim < 0 || other.ndim < 0) | |||||
| return new TensorShape(); | return new TensorShape(); | ||||
| else | else | ||||
| return new TensorShape(NDim + other.NDim); | |||||
| return new TensorShape(ndim + other.ndim); | |||||
| } | } | ||||
| public static implicit operator TensorShape(Shape shape) => new TensorShape(shape.Dimensions); | |||||
| public static implicit operator Shape(TensorShape shape) => new Shape(shape.dims); | |||||
| public static implicit operator TensorShape(int[] dims) => new TensorShape(dims); | public static implicit operator TensorShape(int[] dims) => new TensorShape(dims); | ||||
| public static implicit operator int[](TensorShape shape) => shape.dims; | |||||
| public static implicit operator TensorShape((int, int) dims) => new TensorShape(dims.Item1, dims.Item2); | public static implicit operator TensorShape((int, int) dims) => new TensorShape(dims.Item1, dims.Item2); | ||||
| public static implicit operator TensorShape((int, int, int) dims) => new TensorShape(dims.Item1, dims.Item2, dims.Item3); | public static implicit operator TensorShape((int, int, int) dims) => new TensorShape(dims.Item1, dims.Item2, dims.Item3); | ||||
| public static implicit operator TensorShape((int, int, int, int) dims) => new TensorShape(dims.Item1, dims.Item2, dims.Item3, dims.Item4); | public static implicit operator TensorShape((int, int, int, int) dims) => new TensorShape(dims.Item1, dims.Item2, dims.Item3, dims.Item4); | ||||
| @@ -81,7 +81,7 @@ namespace Tensorflow | |||||
| /// <returns></returns> | /// <returns></returns> | ||||
| public static Tensor _tensor_shape_tensor_conversion_function(TensorShape s, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool as_ref = false) | public static Tensor _tensor_shape_tensor_conversion_function(TensorShape s, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool as_ref = false) | ||||
| { | { | ||||
| var s_list = s.Dimensions; | |||||
| var s_list = s.dims; | |||||
| var int64_value = 0; | var int64_value = 0; | ||||
| foreach(var dim in s_list) | foreach(var dim in s_list) | ||||
| { | { | ||||
| @@ -247,7 +247,7 @@ namespace Tensorflow | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| shape_size = new TensorShape(shape).Size; | |||||
| shape_size = new TensorShape(shape).size; | |||||
| is_same_size = shape_size == nparray.size; | is_same_size = shape_size == nparray.size; | ||||
| } | } | ||||
| @@ -387,10 +387,10 @@ namespace Tensorflow | |||||
| { | { | ||||
| TensorShapeProto shape = new TensorShapeProto(); | TensorShapeProto shape = new TensorShapeProto(); | ||||
| for (int i = 0; i < tshape.NDim; i++) | |||||
| for (int i = 0; i < tshape.ndim; i++) | |||||
| { | { | ||||
| var dim = new TensorShapeProto.Types.Dim(); | var dim = new TensorShapeProto.Types.Dim(); | ||||
| dim.Size = tshape.Dimensions[i]; | |||||
| dim.Size = tshape.dims[i]; | |||||
| //dim.Name = $"dim_{i}"; | //dim.Name = $"dim_{i}"; | ||||
| shape.Dim.Add(dim); | shape.Dim.Add(dim); | ||||
| @@ -42,10 +42,10 @@ namespace Tensorflow | |||||
| verify_shape: false, | verify_shape: false, | ||||
| allow_broadcast: false); | allow_broadcast: false); | ||||
| public static Tensor zeros(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) | |||||
| public static Tensor zeros(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) | |||||
| => array_ops.zeros(shape, dtype, name); | => array_ops.zeros(shape, dtype, name); | ||||
| public static Tensor ones(Shape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) | |||||
| public static Tensor ones(TensorShape shape, TF_DataType dtype = TF_DataType.TF_FLOAT, string name = null) | |||||
| => array_ops.ones(shape, dtype, name); | => array_ops.ones(shape, dtype, name); | ||||
| public static Tensor size(Tensor input, | public static Tensor size(Tensor input, | ||||
| @@ -67,7 +67,7 @@ namespace Tensorflow | |||||
| VariableSynchronization synchronization = VariableSynchronization.Auto, | VariableSynchronization synchronization = VariableSynchronization.Auto, | ||||
| VariableAggregation aggregation = VariableAggregation.None) | VariableAggregation aggregation = VariableAggregation.None) | ||||
| { | { | ||||
| bool is_scalar = !(shape is null) && shape.NDim == 0; | |||||
| bool is_scalar = !(shape is null) && shape.ndim == 0; | |||||
| if (initializer is IInitializer init) | if (initializer is IInitializer init) | ||||
| { | { | ||||
| @@ -130,7 +130,7 @@ namespace TensorFlowNET.Examples | |||||
| var counts = np.zeros((k, num_classes), np.float32); | var counts = np.zeros((k, num_classes), np.float32); | ||||
| sw.Start(); | sw.Start(); | ||||
| foreach (var i in range(idx.Length)) | |||||
| foreach (var i in range(idx.Count)) | |||||
| { | { | ||||
| var x = mnist.train.labels[i]; | var x = mnist.train.labels[i]; | ||||
| counts[idx[i]] += x; | counts[idx[i]] += x; | ||||
| @@ -42,10 +42,10 @@ namespace TensorFlowNET.Examples | |||||
| fit(X, y); | fit(X, y); | ||||
| // Create a regular grid and classify each point | // Create a regular grid and classify each point | ||||
| float x_min = X.amin(0).Data<float>(0) - 0.5f; | |||||
| float y_min = X.amin(0).Data<float>(1) - 0.5f; | |||||
| float x_max = X.amax(0).Data<float>(0) + 0.5f; | |||||
| float y_max = X.amax(0).Data<float>(1) + 0.5f; | |||||
| float x_min = X.amin(0).Data<float>()[0] - 0.5f; | |||||
| float y_min = X.amin(0).Data<float>()[1] - 0.5f; | |||||
| float x_max = X.amax(0).Data<float>()[1] + 0.5f; | |||||
| float y_max = X.amax(0).Data<float>()[1] + 0.5f; | |||||
| var (xx, yy) = np.meshgrid(np.linspace(x_min, x_max, 30), np.linspace(y_min, y_max, 30)); | var (xx, yy) = np.meshgrid(np.linspace(x_min, x_max, 30), np.linspace(y_min, y_max, 30)); | ||||
| with(tf.Session(), sess => | with(tf.Session(), sess => | ||||
| @@ -243,7 +243,7 @@ namespace TensorFlowNET.Examples.ImageProcess | |||||
| return with(tf.variable_scope("Flatten_layer"), delegate | return with(tf.variable_scope("Flatten_layer"), delegate | ||||
| { | { | ||||
| var layer_shape = layer.TensorShape; | var layer_shape = layer.TensorShape; | ||||
| var num_features = layer_shape[new Slice(1, 4)].Size; | |||||
| var num_features = layer_shape[new Slice(1, 4)].size; | |||||
| var layer_flat = tf.reshape(layer, new[] { -1, num_features }); | var layer_flat = tf.reshape(layer, new[] { -1, num_features }); | ||||
| return layer_flat; | return layer_flat; | ||||
| @@ -179,12 +179,12 @@ namespace TensorFlowNET.Examples.ImageProcess | |||||
| private (Operation, Tensor, Tensor, Tensor, Tensor) add_final_retrain_ops(int class_count, string final_tensor_name, | private (Operation, Tensor, Tensor, Tensor, Tensor) add_final_retrain_ops(int class_count, string final_tensor_name, | ||||
| Tensor bottleneck_tensor, bool quantize_layer, bool is_training) | Tensor bottleneck_tensor, bool quantize_layer, bool is_training) | ||||
| { | { | ||||
| var (batch_size, bottleneck_tensor_size) = (bottleneck_tensor.TensorShape.Dimensions[0], bottleneck_tensor.TensorShape.Dimensions[1]); | |||||
| var (batch_size, bottleneck_tensor_size) = (bottleneck_tensor.TensorShape.dims[0], bottleneck_tensor.TensorShape.dims[1]); | |||||
| with(tf.name_scope("input"), scope => | with(tf.name_scope("input"), scope => | ||||
| { | { | ||||
| bottleneck_input = tf.placeholder_with_default( | bottleneck_input = tf.placeholder_with_default( | ||||
| bottleneck_tensor, | bottleneck_tensor, | ||||
| shape: bottleneck_tensor.TensorShape.Dimensions, | |||||
| shape: bottleneck_tensor.TensorShape.dims, | |||||
| name: "BottleneckInputPlaceholder"); | name: "BottleneckInputPlaceholder"); | ||||
| ground_truth_input = tf.placeholder(tf.int64, new TensorShape(batch_size), name: "GroundTruthInput"); | ground_truth_input = tf.placeholder(tf.int64, new TensorShape(batch_size), name: "GroundTruthInput"); | ||||
| @@ -206,7 +206,7 @@ namespace TensorFlowNET.Examples.ImageProcess | |||||
| RefVariable layer_biases = null; | RefVariable layer_biases = null; | ||||
| with(tf.name_scope("biases"), delegate | with(tf.name_scope("biases"), delegate | ||||
| { | { | ||||
| layer_biases = tf.Variable(tf.zeros(class_count), name: "final_biases"); | |||||
| layer_biases = tf.Variable(tf.zeros(new TensorShape(class_count)), name: "final_biases"); | |||||
| variable_summaries(layer_biases); | variable_summaries(layer_biases); | ||||
| }); | }); | ||||
| @@ -662,7 +662,7 @@ namespace TensorFlowNET.Examples.ImageProcess | |||||
| var train_summary = results[0]; | var train_summary = results[0]; | ||||
| // TODO | // TODO | ||||
| train_writer.add_summary(train_summary, i); | |||||
| // train_writer.add_summary(train_summary, i); | |||||
| // Every so often, print out how well the graph is training. | // Every so often, print out how well the graph is training. | ||||
| bool is_last_step = (i + 1 == how_many_training_steps); | bool is_last_step = (i + 1 == how_many_training_steps); | ||||
| @@ -687,9 +687,9 @@ namespace TensorFlowNET.Examples.ImageProcess | |||||
| new FeedItem(bottleneck_input, validation_bottlenecks), | new FeedItem(bottleneck_input, validation_bottlenecks), | ||||
| new FeedItem(ground_truth_input, validation_ground_truth)); | new FeedItem(ground_truth_input, validation_ground_truth)); | ||||
| (string validation_summary, float validation_accuracy) = (results[0], results[1]); | |||||
| validation_writer.add_summary(validation_summary, i); | |||||
| //(string validation_summary, float validation_accuracy) = (results[0], results[1]); | |||||
| float validation_accuracy = results[1]; | |||||
| // validation_writer.add_summary(validation_summary, i); | |||||
| print($"{DateTime.Now}: Step {i + 1}: Validation accuracy = {validation_accuracy * 100}% (N={len(validation_bottlenecks)}) {sw.ElapsedMilliseconds}ms"); | print($"{DateTime.Now}: Step {i + 1}: Validation accuracy = {validation_accuracy * 100}% (N={len(validation_bottlenecks)}) {sw.ElapsedMilliseconds}ms"); | ||||
| sw.Restart(); | sw.Restart(); | ||||
| } | } | ||||
| @@ -86,11 +86,11 @@ namespace TensorFlowNET.Examples | |||||
| // convert x_train | // convert x_train | ||||
| train_data = new NDArray(np.int32, (x_train.size, 256)); | train_data = new NDArray(np.int32, (x_train.size, 256)); | ||||
| for (int i = 0; i < x_train.size; i++) | for (int i = 0; i < x_train.size; i++) | ||||
| train_data[i] = x_train[i].Data<string>(0).Split(',').Select(x => int.Parse(x)).ToArray(); | |||||
| train_data[i] = x_train[i].Data<string>()[1].Split(',').Select(x => int.Parse(x)).ToArray(); | |||||
| test_data = new NDArray(np.int32, (x_test.size, 256)); | test_data = new NDArray(np.int32, (x_test.size, 256)); | ||||
| for (int i = 0; i < x_test.size; i++) | for (int i = 0; i < x_test.size; i++) | ||||
| test_data[i] = x_test[i].Data<string>(0).Split(',').Select(x => int.Parse(x)).ToArray(); | |||||
| test_data[i] = x_test[i].Data<string>()[1].Split(',').Select(x => int.Parse(x)).ToArray(); | |||||
| train_labels = y_train; | train_labels = y_train; | ||||
| test_labels = y_test; | test_labels = y_test; | ||||
| @@ -111,10 +111,10 @@ namespace TensorFlowNET.Examples.Utility | |||||
| var num_labels = labels_dense.shape[0]; | var num_labels = labels_dense.shape[0]; | ||||
| var index_offset = np.arange(num_labels) * num_classes; | var index_offset = np.arange(num_labels) * num_classes; | ||||
| var labels_one_hot = np.zeros(num_labels, num_classes); | var labels_one_hot = np.zeros(num_labels, num_classes); | ||||
| for(int row = 0; row < num_labels; row++) | |||||
| var bytes = labels_dense.Data<byte>(); | |||||
| for (int row = 0; row < num_labels; row++) | |||||
| { | { | ||||
| var col = labels_dense.Data<byte>(row); | |||||
| var col = bytes[row]; | |||||
| labels_one_hot.SetData(1.0, row, col); | labels_one_hot.SetData(1.0, row, col); | ||||
| } | } | ||||
| @@ -125,7 +125,7 @@ namespace TensorFlowNET.Examples.Utility | |||||
| { | { | ||||
| var buffer = new byte[sizeof(uint)]; | var buffer = new byte[sizeof(uint)]; | ||||
| var count = bytestream.Read(buffer, 0, 4); | var count = bytestream.Read(buffer, 0, 4); | ||||
| return np.frombuffer(buffer, ">u4").Data<uint>(0); | |||||
| return np.frombuffer(buffer, ">u4").Data<uint>()[0]; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||