From a28aebc5f80630683f50ce934e8584c6b0004beb Mon Sep 17 00:00:00 2001 From: Pablo Tello Date: Mon, 3 Jun 2019 14:59:48 +0100 Subject: COMPMID-2383: DepthwiseConv use output qinfo There was a problem in depthwise_conv where when needing to run permute it was calling auto_init to initialise the temporary tensor with input's qinfo instead of output's qinfo. This patch fixes this and adds some tests to exercise the cases where we have different qinfos Change-Id: I396fbb4d73f6aa5efe03dc2dd727b3e13154d6f5 Signed-off-by: Pablo Tello Reviewed-on: https://review.mlplatform.org/c/1270 Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Reviewed-by: Giuseppe Rossini Reviewed-by: Georgios Pinitas --- .../fixtures/DepthwiseConvolutionLayerFixture.h | 52 +++++++++++++--------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h') diff --git a/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h b/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h index 9e6dd4bd28..04c073b521 100644 --- a/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h +++ b/tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h @@ -56,10 +56,12 @@ public: public: template - void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type, QuantizationInfo quantization_info, - DataLayout data_layout, ActivationLayerInfo act_info) + void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type, + QuantizationInfo input_quantization_info, QuantizationInfo output_quantization_info, DataLayout data_layout, ActivationLayerInfo act_info) { - _quantization_info = quantization_info; + _input_quantization_info = input_quantization_info; + _output_quantization_info = output_quantization_info; + _data_type = data_type; const DataType bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; @@ -72,8 +74,10 @@ public: weights_shape.set(2, out_shape.z()); const TensorShape biases_shape(weights_shape[2]); - _target = compute_target(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, dilation, depth_multiplier, data_type, bias_data_type, quantization_info, data_layout, act_info); - _reference = compute_reference(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, dilation, depth_multiplier, data_type, bias_data_type, quantization_info, act_info); + _target = compute_target(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, dilation, depth_multiplier, + data_type, bias_data_type, input_quantization_info, output_quantization_info, data_layout, act_info); + _reference = compute_reference(in_shape, weights_shape, biases_shape, out_shape, pad_stride_info, dilation, depth_multiplier, + data_type, bias_data_type, input_quantization_info, output_quantization_info, act_info); } protected: @@ -108,7 +112,9 @@ protected: TensorType compute_target(TensorShape input_shape, TensorShape weights_shape, TensorShape biases_shape, TensorShape output_shape, PadStrideInfo &pad_stride_info, Size2D dilation, unsigned int depth_multiplier, - const DataType data_type, const DataType bias_data_type, const QuantizationInfo quantization_info, const DataLayout data_layout, ActivationLayerInfo act_info) + const DataType data_type, const DataType bias_data_type, + const QuantizationInfo input_quantization_info, const QuantizationInfo output_quantization_info, + const DataLayout data_layout, ActivationLayerInfo act_info) { if(data_layout == DataLayout::NHWC) { @@ -118,10 +124,10 @@ protected: } // Create tensors - TensorType src = create_tensor(input_shape, data_type, 1, quantization_info, data_layout); - TensorType weights = create_tensor(weights_shape, data_type, 1, quantization_info, data_layout); - TensorType biases = create_tensor(biases_shape, bias_data_type, 1, quantization_info, data_layout); - TensorType dst = create_tensor(output_shape, data_type, 1, quantization_info, data_layout); + TensorType src = create_tensor(input_shape, data_type, 1, input_quantization_info, data_layout); + TensorType weights = create_tensor(weights_shape, data_type, 1, input_quantization_info, data_layout); + TensorType biases = create_tensor(biases_shape, bias_data_type, 1, input_quantization_info, data_layout); + TensorType dst = create_tensor(output_shape, data_type, 1, output_quantization_info, data_layout); // Create Depthwise Convolution configure function FunctionType dwc; @@ -154,26 +160,30 @@ protected: return dst; } - SimpleTensor compute_reference(const TensorShape &in_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const TensorShape &out_shape, const PadStrideInfo &pad_stride_info, + SimpleTensor compute_reference(const TensorShape &in_shape, const TensorShape &weights_shape, const TensorShape &biases_shape, const TensorShape &out_shape, + const PadStrideInfo &pad_stride_info, const Size2D &dilation, unsigned int depth_multiplier, - const DataType data_type, const DataType bias_data_type, const QuantizationInfo quantization_info, ActivationLayerInfo act_info) + const DataType data_type, const DataType bias_data_type, + const QuantizationInfo input_quantization_info, const QuantizationInfo output_quantization_info, + ActivationLayerInfo act_info) { - SimpleTensor src{ in_shape, data_type, 1, quantization_info }; - SimpleTensor weights{ weights_shape, data_type, 1, quantization_info }; - SimpleTensor biases{ biases_shape, bias_data_type, 1, quantization_info }; + SimpleTensor src{ in_shape, data_type, 1, input_quantization_info }; + SimpleTensor weights{ weights_shape, data_type, 1, input_quantization_info }; + SimpleTensor biases{ biases_shape, bias_data_type, 1, input_quantization_info }; fill(src, 0); fill(weights, 1); fill(biases, 2); - SimpleTensor depth_out = reference::depthwise_convolution(src, weights, biases, out_shape, pad_stride_info, depth_multiplier, dilation); + SimpleTensor depth_out = reference::depthwise_convolution(src, weights, biases, out_shape, pad_stride_info, depth_multiplier, dilation, output_quantization_info); return (act_info.enabled()) ? reference::activation_layer(depth_out, act_info) : depth_out; } TensorType _target{}; SimpleTensor _reference{}; DataType _data_type{}; - QuantizationInfo _quantization_info{}; + QuantizationInfo _input_quantization_info{}; + QuantizationInfo _output_quantization_info{}; }; template @@ -185,7 +195,7 @@ public: ActivationLayerInfo act_info) { DepthwiseConvolutionLayerValidationGenericFixture::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier, - data_type, QuantizationInfo(), data_layout, act_info); + data_type, QuantizationInfo(), QuantizationInfo(), data_layout, act_info); } }; @@ -194,11 +204,11 @@ class DepthwiseConvolutionLayerValidationQuantizedFixture : public DepthwiseConv { public: template - void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type, QuantizationInfo quantization_info, - DataLayout data_layout, ActivationLayerInfo act_info) + void setup(TensorShape in_shape, Size2D kernel_size, PadStrideInfo pad_stride_info, Size2D dilation, unsigned int depth_multiplier, DataType data_type, + QuantizationInfo input_quantization_info, QuantizationInfo output_quantization_info, DataLayout data_layout, ActivationLayerInfo act_info) { DepthwiseConvolutionLayerValidationGenericFixture::setup(in_shape, kernel_size, pad_stride_info, dilation, depth_multiplier, - data_type, quantization_info, data_layout, act_info); + data_type, input_quantization_info, output_quantization_info, data_layout, act_info); } }; } // namespace validation -- cgit v1.2.1