From 4db89af0499db1e9c0c8d65d652633c87e72b2d0 Mon Sep 17 00:00:00 2001 From: Eli Belash Date: Sun, 8 Sep 2019 17:01:43 +0300 Subject: [PATCH] TensorShape: fixed size computation when None is used. --- src/TensorFlowNET.Core/Tensors/TensorShape.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/TensorFlowNET.Core/Tensors/TensorShape.cs b/src/TensorFlowNET.Core/Tensors/TensorShape.cs index 734e9bc5..b2161d48 100644 --- a/src/TensorFlowNET.Core/Tensors/TensorShape.cs +++ b/src/TensorFlowNET.Core/Tensors/TensorShape.cs @@ -33,7 +33,23 @@ namespace Tensorflow /// /// Returns the size this shape represents. /// - public int size => shape.Size; + public int size + { + get + { + var dims = shape.Dimensions; + var computed = 1; + for (int i = 0; i < dims.Length; i++) + { + var val = dims[i]; + if (val <= 0) + continue; + computed *= val; + } + + return computed; + } + } public TensorShape(TensorShapeProto proto) {