Skip to content

Commit

Permalink
add onnx upsampleOp convert
Browse files Browse the repository at this point in the history
Change-Id: I88566fbccc0c37ecb82d74c75b9c24995118b0eb
  • Loading branch information
ljqljq111 authored and charlesxzb committed Feb 15, 2023
1 parent 1e17fdc commit 5315aa6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/transform/OnnxConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def __init__(self,
"TopK": lambda node: self.convert_topk_op(node),
"Transpose": lambda node: self.convert_transpose_op(node),
"Unsqueeze": lambda node: self.convert_unsqueeze_op(node),
"Upsample":lambda node:self.convert_upsample_op(node),
"Where": lambda node: self.convert_where_op(node),
}

Expand Down Expand Up @@ -942,6 +943,27 @@ def resize_to_interp(self, onnx_node, op, input_shape, output_shape, scale_h, sc
new_op = self.mlir.create_interp_op(operands, output_shape, **p)
self.addOperand(onnx_node.name, new_op)

def convert_upsample_op(self, onnx_node):
assert (onnx_node.op_type == "Upsample")
mode = onnx_node.attrs.get("mode", "nearest")
op = self.getOperand(onnx_node.inputs[0])
input_shape = self.getShape(onnx_node.inputs[0])
scale_factor = []
sizes = []
scale_factor = self.getWeight(onnx_node.inputs[1])
sizes = input_shape * scale_factor
output_shape = [int(i) for i in sizes]
scale_h = scale_factor[2] # scale [n, c, h, w]
scale_w = scale_factor[3]
coord_mode = onnx_node.attrs.get("coordinate_transformation_mode", "half_pixel")
if mode == b'nearest' and scale_h == int(scale_h) and scale_w == int(scale_w):
self.resize_to_upsample(onnx_node, op, input_shape, output_shape, scale_h, scale_w)
return
else:
self.resize_to_interp(onnx_node, op, input_shape, output_shape, scale_h, scale_w, mode,
coord_mode)
return

def convert_resize_op(self, onnx_node):
assert (onnx_node.op_type == "Resize")
mode = onnx_node.attrs.get("mode", "nearest")
Expand Down

0 comments on commit 5315aa6

Please sign in to comment.