From 20dc0f0acc60ffb8f1181f56380dbb77e741abf9 Mon Sep 17 00:00:00 2001 From: wangtao Date: Wed, 25 Aug 2021 09:59:55 +0800 Subject: [PATCH 1/4] transpose onnx pad reshape Signed-off-by: wangtao --- tools/nntool/importer/onnx/handlers/backend/pad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/nntool/importer/onnx/handlers/backend/pad.py b/tools/nntool/importer/onnx/handlers/backend/pad.py index 7aaa1a7d8..3719abf83 100644 --- a/tools/nntool/importer/onnx/handlers/backend/pad.py +++ b/tools/nntool/importer/onnx/handlers/backend/pad.py @@ -41,7 +41,7 @@ def _common(cls, node, mode='constant', pads=None, constant_value=0, **kwargs): x = inputs[0] x_shape = x[2].shape - apads = np.array(pads).reshape((-1, 2)) + apads = np.array(pads).reshape((2,-1)).T if cls.is_constant(x): logger.info("reducing %s to a constant", valid_name) val = cls.get_constant(x) From d8daa860d027692dcb1fb6ff97e60447fcd11a45 Mon Sep 17 00:00:00 2001 From: wangtao Date: Thu, 9 Sep 2021 17:17:00 +0800 Subject: [PATCH 2/4] fix bug of onnx slice op and quantization pool method --- tools/nntool/importer/onnx/handlers/backend/slice.py | 3 ++- tools/nntool/quantization/symmetric/kernels/pool.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/nntool/importer/onnx/handlers/backend/slice.py b/tools/nntool/importer/onnx/handlers/backend/slice.py index 37363c171..24226f87e 100644 --- a/tools/nntool/importer/onnx/handlers/backend/slice.py +++ b/tools/nntool/importer/onnx/handlers/backend/slice.py @@ -60,7 +60,8 @@ def _common(cls, node, starts, ends, axes, steps, **kwargs): if step < 0: p_shape.append((begin - end)//-step) else: - p_shape.append((end - begin)//step) + # p_shape.append((end - begin)//step) + p_shape.append(int(np.ceil((end - begin)/step))) #test on yolox wrong index number except ValueError: p_slices.append((0, dim, 1)) diff --git a/tools/nntool/quantization/symmetric/kernels/pool.py b/tools/nntool/quantization/symmetric/kernels/pool.py index b893b9aa0..d760a01dc 100644 --- a/tools/nntool/quantization/symmetric/kernels/pool.py +++ b/tools/nntool/quantization/symmetric/kernels/pool.py @@ -109,7 +109,7 @@ def execute(cls, params, in_tensor = np.pad(in_tensor, params.padding.numpy_pad_shape(in_dims), mode='constant', - constant_values=qrec.in_qs[0].pad_zero_point) + constant_values=qrec.in_qs[0].zero_point) #no pad_zero_point pad_w = params.padding.w pad_h = params.padding.h else: From e1fb6339dfd9babb634497187eca0e9ccb7fdf07 Mon Sep 17 00:00:00 2001 From: longingji Date: Thu, 11 Nov 2021 10:26:22 +0800 Subject: [PATCH 3/4] fix bugs of input rgb img (h,w,c) transpose as (c,h,w) Signed-off-by: longingji --- tools/nntool/quantization/float/kernels/tensor_functions.py | 3 ++- .../quantization/symmetric/kernels/tensor_functions.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/nntool/quantization/float/kernels/tensor_functions.py b/tools/nntool/quantization/float/kernels/tensor_functions.py index 7a16b6f89..2ffd27ddd 100644 --- a/tools/nntool/quantization/float/kernels/tensor_functions.py +++ b/tools/nntool/quantization/float/kernels/tensor_functions.py @@ -46,7 +46,8 @@ def execute(cls, params, in_shape = tuple(dim for dim in in_tensor.shape if dim > 1) expected_shape = tuple(dim for dim in params.dims.shape if dim > 1) if in_shape != expected_shape: - raise ValueError(f'{params.name} received input of shape {in_tensor.shape} but expecting {params.dims.shape}') + in_tensor = np.transpose(in_tensor, (2,0,1)) #input rgb (h,w,c)=>(c,h,w) + # raise ValueError(f'{params.name} received input of shape {in_tensor.shape} but expecting {params.dims.shape}') in_tensor = in_tensor.reshape(params.dims.shape) else: in_tensor = resize(in_tensor, params.dims.shape) diff --git a/tools/nntool/quantization/symmetric/kernels/tensor_functions.py b/tools/nntool/quantization/symmetric/kernels/tensor_functions.py index e5cf00a3e..5a8fc00b2 100644 --- a/tools/nntool/quantization/symmetric/kernels/tensor_functions.py +++ b/tools/nntool/quantization/symmetric/kernels/tensor_functions.py @@ -38,8 +38,9 @@ def execute(cls, params, expected_shape = tuple( dim for dim in params.dims.shape if dim > 1) if in_shape != expected_shape: - raise ValueError( - f'{params.name} received input of shape {in_tensor.shape} but expecting {params.dims.shape}') + in_tensor = np.transpose(in_tensor, (2,0,1)) #input rgb (h,w,c)=>(c,h,w) + # raise ValueError( + # f'{params.name} received input of shape {in_tensor.shape} but expecting {params.dims.shape}') in_tensor = in_tensor.reshape(params.dims.shape) else: in_tensor = resize(in_tensor, params.dims.shape) From f7fa8d7a843fc1f813407e0ff1c595a1b5874730 Mon Sep 17 00:00:00 2001 From: longingji Date: Wed, 17 Nov 2021 15:11:15 +0800 Subject: [PATCH 4/4] update padv2 to can compile uint8 yolov3 tflite Signed-off-by: longingji --- tools/nntool/importer/tflite2/handlers/backend/padv2.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/nntool/importer/tflite2/handlers/backend/padv2.py b/tools/nntool/importer/tflite2/handlers/backend/padv2.py index 26016d418..f91e39050 100644 --- a/tools/nntool/importer/tflite2/handlers/backend/padv2.py +++ b/tools/nntool/importer/tflite2/handlers/backend/padv2.py @@ -23,7 +23,7 @@ @tflite_op("PADV2") class PadV2(PadMixin, BackendHandler): - +# xinglong debug use pad.py code here. can compile uint8 yolov3 tflite @classmethod def _common(cls, node: TFLiteNode, **kwargs): @@ -31,9 +31,7 @@ def _common(cls, node: TFLiteNode, **kwargs): inputs = [all_nodes[t] for t in node.input] pads = list(cls._verify_constant(inputs[1])) node.input[1].used = True - pad_vals = list((v, v) for v in cls._verify_constant(inputs[2])) - node.input[2].used = True - return super(PadV2, cls)._common(node, pads=pads, pad_vals=pad_vals, **kwargs) + return super(PadV2, cls)._common(node, pads=pads, **kwargs) @classmethod def version_1(cls, node: TFLiteNode, **kwargs):