Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onnx importer backend pad reshape transpose #264

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/nntool/importer/onnx/handlers/backend/pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tools/nntool/importer/onnx/handlers/backend/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 2 additions & 4 deletions tools/nntool/importer/tflite2/handlers/backend/padv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@

@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):

all_nodes = kwargs['all_nodes']
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):
Expand Down
3 changes: 2 additions & 1 deletion tools/nntool/quantization/float/kernels/tensor_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/nntool/quantization/symmetric/kernels/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down