From 65606cff10c5f617b8ee92ad1898b0262176262a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9E=A5=EC=A7=80=EC=84=AD/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Fri, 31 Aug 2018 17:22:05 +0900 Subject: [PATCH] Add a default param to asTensorShape() to apply conditionally (#2464) This commit add a default param to asTensorShape() to apply conditionally dimension coorection. In some cases, in incorrect dimensions is required. For example, intput_size is 1 in LSTM. The input-to-input weights([num_units, input_size]) of LSTM is used as the weight of the FullyConnected. The FullyConnected's weight must be greater or equal than 2-dimensions. However, if the dimension correction is applied to input_to_input_weights with input_size equal to 1, it will be changed to 1-D. So input_to_input_weights is not used by the weight of FullyConnected. Signed-off-by: jiseob.jang --- runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h b/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h index 470e76c..d4c5dd0 100644 --- a/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h +++ b/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h @@ -5,7 +5,8 @@ #include "internal/Swizzle.h" #include "internal/Model.h" -inline ::arm_compute::TensorShape asTensorShape(const internal::tflite::operand::Shape &shape) +inline ::arm_compute::TensorShape asTensorShape(const internal::tflite::operand::Shape &shape, + bool apply_dim_correction = true) { const uint32_t rank = shape.rank(); @@ -15,10 +16,14 @@ inline ::arm_compute::TensorShape asTensorShape(const internal::tflite::operand: for (uint32_t axis = 0; axis < rank; ++axis) { - // NOTE Do NOT update TensorShape with operator[] (in ::arm_compute::Dimensions) - // TensorShape::set applies dimension correction after value update. - // Various asserts in ARMCompute work only when this correction is applied. - res.set(ToARMComputeAxis(rank, axis).value(), shape.dim(axis)); + // NOTE In some cases, in incorrect dimensions is required. + // For example, intput_size is 1 in LSTM. The input-to-input weights([num_units, input_size]) of + // LSTM is used as the weight of the FullyConnected. + // The FullyConnected's weight must be greater or equal than 2-dimensions. + // However, if the dimension correction is applied to input_to_input_weights with input_size + // equal to 1, it will be changed to 1-D. + // So input_to_input_weights is not used by the weight of FullyConnected. + res.set(ToARMComputeAxis(rank, axis).value(), shape.dim(axis), apply_dim_correction); } return res; -- 2.7.4