From fbcfd5d469900c1f10405a95b43a55d0912d2600 Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 11 May 2021 16:50:35 +0900 Subject: [PATCH 01/14] [Caffe Frontend] adding Reduction op --- python/tvm/relay/frontend/caffe.py | 31 +++++++++++++++++++++ tests/python/frontend/caffe/test_forward.py | 24 ++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index caf4f1a14741..c5a81ae88f27 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -63,6 +63,7 @@ def __init__(self, init_layer_dict, predict_layer, exp_tab): "Slice": self.convert_slice, "Softmax": self.convert_softmax, "TanH": self.convert_tanh, + "Reduction": self.convert_reduction, } def convert_flatten(self, op): @@ -558,6 +559,36 @@ def convert_tanh(self, op): out = _op.tanh(in_expr) return out + def convert_reduction(self, op): + """ Convert Reduction layer """ + reduction_dic = ["NOP", "SUM", "ASUM", "SUMSQ", "MEAN"] + inputs = op.bottom + in_expr = self.exp_tab.get_expr(inputs[0]) + method = op.reduction_param.operation + axis = op.reduction_param.axis + coeff = op.reduction_param.coeff + if reduction_dic[method] == "MEAN": + coeff /= len(inputs) + coeff_expr = self.exp_tab.new_const(np.asarray(coeff, np.float32)) + + if reduction_dic[method] == "SUM": + out = _op.sum(in_expr, axis=axis) + elif reduction_dic[method] == "MEAN": + out = _op.mean(in_expr, axis=axis) + elif reduction_dic[method] == "ASUM": + in_expr = _op.abs(in_expr) + out = _op.sum(in_expr, axis=axis) + elif reduction_dic[method] == "SUMSQ": + in_expr = _op.multiply(in_expr, in_expr) + out = _op.sum(in_expr, axis=axis) + else: + raise tvm.error.OpAttributeInvalid( + "reduction method:{} is invalid in Caffe frontend.".format(method) + ) + + out = _op.multiply(out, coeff_expr) + return out + def convert_crop(self, op): """ Convert Crop layer """ inputs = op.bottom diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index d0f87fcc21c7..c7dd224ad4f0 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -763,6 +763,29 @@ def test_forward_TanH(): _test_tanh(np.random.rand(10).astype(np.float32)) +####################################################################### +# Reduction +# ----------- + + +def _test_reduction(data, **kwargs): + """ One iteration of Reduction """ + _test_op(data, L.Reduction, "Reduction", **kwargs) + + +def test_forward_Reduction(): + """ Reduction """ + reduction_op = {"SUM":1, "ASUM":2, "SUMSQ":3, "MEAN":4} + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0.) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0, coeff=0.) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0, coeff=0.) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0, coeff=0.) + + ####################################################################### # Mobilenetv2 # ----------- @@ -907,6 +930,7 @@ def test_forward_Inceptionv1(): # Reshape test_forward_Reshape() test_forward_Flatten() + test_forward_Reduction() # Math test_forward_Concat() From 655d9ef806744005b9448a3b5742b24dc976b5cb Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 11 May 2021 20:06:56 +0900 Subject: [PATCH 02/14] reformatting Reduction op test script --- tests/python/frontend/caffe/test_forward.py | 34 +++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index c7dd224ad4f0..f51e110de26d 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -775,15 +775,31 @@ def _test_reduction(data, **kwargs): def test_forward_Reduction(): """ Reduction """ - reduction_op = {"SUM":1, "ASUM":2, "SUMSQ":3, "MEAN":4} - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0.) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0, coeff=0.) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0, coeff=0.) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0, coeff=0.) + reduction_op = {"SUM": 1, "ASUM": 2, "SUMSQ": 3, "MEAN": 4} + _test_reduction( + np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0 + ) + _test_reduction( + np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0. + ) + _test_reduction( + np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0 + ) + _test_reduction( + np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0, coeff=0. + ) + _test_reduction( + np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0 + ) + _test_reduction( + np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0, coeff=0. + ) + _test_reduction( + np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0 + ) + _test_reduction( + np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0, coeff=0. + ) ####################################################################### From f80ba3efd654146da0d87f7c64b7881ea662927c Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 11 May 2021 20:26:21 +0900 Subject: [PATCH 03/14] reformatting Reduction test script --- tests/python/frontend/caffe/test_forward.py | 24 +++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index f51e110de26d..8e27fa420fdf 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -776,29 +776,21 @@ def _test_reduction(data, **kwargs): def test_forward_Reduction(): """ Reduction """ reduction_op = {"SUM": 1, "ASUM": 2, "SUMSQ": 3, "MEAN": 4} + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0) _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0 + np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0.0 ) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0) _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0. + np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0, coeff=0.0 ) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0) _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0 + np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0, coeff=0.0 ) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0) _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0, coeff=0. - ) - _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0 - ) - _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0, coeff=0. - ) - _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0 - ) - _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0, coeff=0. + np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0, coeff=0.0 ) From 8d8af41e8fb5c64fd71a79d75178fba3b3fee61c Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 18 May 2021 14:41:42 +0900 Subject: [PATCH 04/14] [Caffe frontend] Reduction op - adding more test cases; handling '0 < axis < num_axes - 1' case to give the result equivalent to Caffe framework - skipping Relay multiplication if coeff is 1 Signed-off-by: zotanika --- python/tvm/relay/frontend/caffe.py | 14 +++++++++--- tests/python/frontend/caffe/test_forward.py | 25 +++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index c5a81ae88f27..db5228f1f3af 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -562,14 +562,21 @@ def convert_tanh(self, op): def convert_reduction(self, op): """ Convert Reduction layer """ reduction_dic = ["NOP", "SUM", "ASUM", "SUMSQ", "MEAN"] + inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) method = op.reduction_param.operation axis = op.reduction_param.axis coeff = op.reduction_param.coeff - if reduction_dic[method] == "MEAN": - coeff /= len(inputs) coeff_expr = self.exp_tab.new_const(np.asarray(coeff, np.float32)) + num_axes = len(_infer_shape(in_expr)) + + # Currently, only reduction along ALL "tail" axes is supported in Caffe; + # reduction of axis M through N, where N < num_axes - 1, is unsupported. + if axis > 0 and axis < num_axes - 1: + for _axis in reversed(range(axis + 1, num_axes)): + in_expr = _op.sum(in_expr, axis=_axis) + in_expr = _op.squeeze(in_expr) if reduction_dic[method] == "SUM": out = _op.sum(in_expr, axis=axis) @@ -586,7 +593,8 @@ def convert_reduction(self, op): "reduction method:{} is invalid in Caffe frontend.".format(method) ) - out = _op.multiply(out, coeff_expr) + if float(coeff) != 1.0: + out = _op.multiply(out, coeff_expr) return out def convert_crop(self, op): diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index 8e27fa420fdf..5c35d9870fa1 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -777,21 +777,42 @@ def test_forward_Reduction(): """ Reduction """ reduction_op = {"SUM": 1, "ASUM": 2, "SUMSQ": 3, "MEAN": 4} _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0) + _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=3) + _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=1) _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0.0 + np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0.5 ) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0) + _test_reduction( + np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=3, coeff=5.0 + ) + _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"]) + _test_reduction(np.random.rand(10, 20).astype(np.float32), operation=reduction_op["ASUM"], axis=1) + _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["ASUM"], axis=3) _test_reduction( np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0, coeff=0.0 ) + _test_reduction( + np.random.rand(10, 20, 30).astype(np.float32), operation=reduction_op["ASUM"], axis=2, coeff=7.0 + ) + _test_reduction( + np.random.rand(10, 20, 30, 40, 10).astype(np.float32), operation=reduction_op["ASUM"], axis=3, coeff=1.0 + ) _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0) + _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUMSQ"], axis=3) _test_reduction( np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0, coeff=0.0 ) + _test_reduction( + np.random.rand(10, 20, 30, 40, 50).astype(np.float32), operation=reduction_op["SUMSQ"], axis=4, coeff=2.0 + ) _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0) + _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["MEAN"], axis=3) _test_reduction( np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0, coeff=0.0 ) + _test_reduction( + np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["MEAN"], axis=3, coeff=2.0 + ) ####################################################################### From be443dd5dbf341e520baf18dd24987259b333a67 Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 18 May 2021 15:11:59 +0900 Subject: [PATCH 05/14] linting test script --- tests/python/frontend/caffe/test_forward.py | 49 ++++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index 5c35d9870fa1..d1b5e7e3f489 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -777,41 +777,68 @@ def test_forward_Reduction(): """ Reduction """ reduction_op = {"SUM": 1, "ASUM": 2, "SUMSQ": 3, "MEAN": 4} _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0) - _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=3) - _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=1) + _test_reduction( + np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=3 + ) + _test_reduction( + np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=1 + ) _test_reduction( np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0.5 ) _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=3, coeff=5.0 + np.random.rand(10, 20, 30, 40).astype(np.float32), + operation=reduction_op["SUM"], + axis=3, + coeff=5.0, ) _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"]) - _test_reduction(np.random.rand(10, 20).astype(np.float32), operation=reduction_op["ASUM"], axis=1) - _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["ASUM"], axis=3) + _test_reduction( + np.random.rand(10, 20).astype(np.float32), operation=reduction_op["ASUM"], axis=1 + ) + _test_reduction( + np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["ASUM"], axis=3 + ) _test_reduction( np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0, coeff=0.0 ) _test_reduction( - np.random.rand(10, 20, 30).astype(np.float32), operation=reduction_op["ASUM"], axis=2, coeff=7.0 + np.random.rand(10, 20, 30).astype(np.float32), + operation=reduction_op["ASUM"], + axis=2, + coeff=7.0, ) _test_reduction( - np.random.rand(10, 20, 30, 40, 10).astype(np.float32), operation=reduction_op["ASUM"], axis=3, coeff=1.0 + np.random.rand(10, 20, 30, 40, 10).astype(np.float32), + operation=reduction_op["ASUM"], + axis=3, + coeff=1.0, ) _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0) - _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUMSQ"], axis=3) + _test_reduction( + np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUMSQ"], axis=3 + ) _test_reduction( np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0, coeff=0.0 ) _test_reduction( - np.random.rand(10, 20, 30, 40, 50).astype(np.float32), operation=reduction_op["SUMSQ"], axis=4, coeff=2.0 + np.random.rand(10, 20, 30, 40, 50).astype(np.float32), + operation=reduction_op["SUMSQ"], + axis=4, + coeff=2.0, ) _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0) - _test_reduction(np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["MEAN"], axis=3) + _test_reduction( + np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["MEAN"], axis=3 + ) _test_reduction( np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0, coeff=0.0 ) _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["MEAN"], axis=3, coeff=2.0 + np.random.rand(10, 20, 30, 40).astype(np.float32), + operation=reduction_op["MEAN"], + axis=3, + coeff=2.0, ) From d361160593f4fb993bd4828a97a205eb69919972 Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 18 May 2021 15:27:25 +0900 Subject: [PATCH 06/14] linting --- python/tvm/relay/frontend/caffe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index db5228f1f3af..ae34352cab93 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -573,7 +573,7 @@ def convert_reduction(self, op): # Currently, only reduction along ALL "tail" axes is supported in Caffe; # reduction of axis M through N, where N < num_axes - 1, is unsupported. - if axis > 0 and axis < num_axes - 1: + if 0 < axis < (num_axes - 1): for _axis in reversed(range(axis + 1, num_axes)): in_expr = _op.sum(in_expr, axis=_axis) in_expr = _op.squeeze(in_expr) From 43e25e552b790ce9a38fdbcfb3ddf2075c253e20 Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 25 May 2021 21:27:06 +0900 Subject: [PATCH 07/14] [Caffe Frontend] Supporting multiple grouped(channel-wise) Deconv op * Handling group > 1 cases, assuming group == output channels * Decomposed into Relay split, transposed conv, and multi-leveled concatenation. * Added some test cases. Signed-off-by: zotanika --- python/tvm/relay/frontend/caffe.py | 63 +++++++++++++++++++-- tests/python/frontend/caffe/test_forward.py | 27 +++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index ae34352cab93..4786c4c88759 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -512,19 +512,72 @@ def convert_deconv(self, op): if weight: kh, kw = params["kernel_size"] weight_shape = [-1, conv_params.num_output, kh, kw] - weight_value = np.asarray(weight.data, np.float32) + if not weight.data: + if conv_params.weight_filler: + _filler = conv_params.weight_filler.value + weight_value = np.full(weight.shape.dim, _filler, np.float32) + else: + raise tvm.error.OpAttributeInvalid("At least weight_filler must be given") + else: + weight_value = np.asarray(weight.data, np.float32) weight_value = np.reshape(weight_value, weight_shape) else: - raise Exception("No weight value of layer {} in caffemodel".format(op.name)) + raise tvm.error.OpAttributeRequired( + "No weight value of layer {} in caffemodel".format(op.name) + ) weight_expr = self.exp_tab.new_const(weight_value, dtype="float32") in_expr = self.exp_tab.get_expr(inputs[0]) - out = _op.nn.conv2d_transpose(data=in_expr, weight=weight_expr, **params) - if bias: + groups = params["groups"] + channels = params["channels"] + + if bias: bias_value = np.asarray(bias.data, np.float32) bias_expr = self.exp_tab.new_const(bias_value, dtype="float32") - out = _op.nn.bias_add(out, bias_expr) + + if groups > channels: + raise tvm.error.OpAttributeInvalid( + "Groups cannot be larger than the number of input channels" + ) + + if groups == channels: + inputs_expr = _op.split(in_expr, groups, axis=1) + weights_expr = _op.split(weight_expr, groups, axis=1) + # Preventing to create Concat layer with too many tensors(> 16) + q = groups >> 4 + r = groups % 16 + + params["groups"] = 1 + params["channels"] = 1 + out = [] + for lc in range(q): + _outputs = [] + _inputs = [inputs_expr[i] for i in range(lc << 4, (lc << 4) + 16)] + _weights = [weights_expr[i] for i in range(lc << 4, (lc << 4) + 16)] + for (i, w) in zip(_inputs, _weights): + _out = _op.nn.conv2d_transpose(data=i, weight=w, **params) + if bias: + _out = _op.nn.bias_add(_out, bias_expr) + _outputs.append(_out) + out.append(_op.concatenate(_outputs, axis=1)) + if r != 0: + _outputs = [] + _inputs = [inputs_expr[i] for i in range(groups - r, groups)] + _weights = [weights_expr[i] for i in range(groups - r, groups)] + for (i, w) in zip(_inputs, _weights): + _out = _op.nn.conv2d_transpose(data=i, weight=w, **params) + if bias: + _out = _op.nn.bias_add(_out, bias_expr) + _outputs.append(_out) + out.append(_op.concatenate(_outputs, axis=1)) + out = _op.concatenate(out, axis=1) + elif groups == 1: + out = _op.nn.conv2d_transpose(data=in_expr, weight=weight_expr, **params) + if bias: + out = _op.nn.bias_add(out, bias_expr) + else: + raise tvm.error.OpAttributeInvalid("Unable to handle.") return out def convert_slice(self, op): diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index 1a284d893d55..786ea8cb92e0 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -452,6 +452,33 @@ def test_forward_Deconvolution(): bias_filler=dict(type="xavier"), ), ) + _test_deconvolution( + data, + convolution_param=dict( + num_output=16, + bias_term=False, + pad=0, + kernel_size=2, + stride=2, + dilation=1, + group=16, + weight_filler=dict(type="xavier"), + bias_filler=dict(type="xavier"), + ), + ) + data = np.random.rand(1, 100, 32, 32).astype(np.float32) + _test_deconvolution( + data, + convolution_param=dict( + num_output=100, + bias_term=False, + pad=0, + kernel_size=2, + stride=2, + dilation=1, + group=100, + ), + ) ####################################################################### From 894f97f98bb860caabc44944def5e08607a0773a Mon Sep 17 00:00:00 2001 From: zotanika Date: Wed, 26 May 2021 11:06:20 +0900 Subject: [PATCH 08/14] [Caffe Frontend] supporting variable number of inputs for Eltwise * extra handling of rest inputs for PROD, SUM, MAX operations * extra testcases Signed-off-by: zotanika --- python/tvm/relay/frontend/caffe.py | 25 +++++++++++-- tests/python/frontend/caffe/test_forward.py | 40 ++++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index 4786c4c88759..5086f7c3407b 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -80,14 +80,13 @@ def convert_flatten(self, op): def convert_eltwise(self, op): """ Convert Eltwise layer """ inputs = op.bottom - assert len(inputs) == 2, "input tensors length should be 2" + assert len(inputs) >= 2, "input tensors length should be larger than 2" + # gethering initial 2 input expressions lhs_expr = self.exp_tab.get_expr(inputs[0]) rhs_expr = self.exp_tab.get_expr(inputs[1]) - lhs_shape = _infer_shape(lhs_expr) rhs_shape = _infer_shape(rhs_expr) - assert lhs_shape == rhs_shape, "input tensors shape should be equal" eltwise_params = op.eltwise_param @@ -97,6 +96,11 @@ def convert_eltwise(self, op): if eltwise_type_dict[eltwise_type] == "PROD": out = _op.multiply(lhs_expr, rhs_expr) + # for rest inputs + for i in range(len(inputs) - 2): + extra_expr = self.exp_tab.get_expr(inputs[i + 2]) + assert _infer_shape(out) == _infer_shape(extra_expr) + out = _op.multiply(out, extra_expr) elif eltwise_type_dict[eltwise_type] == "SUM": if coeff: left_coeff_expr = self.exp_tab.new_const(np.asarray(coeff[0], np.float32)) @@ -106,8 +110,23 @@ def convert_eltwise(self, op): out = _op.add(lhs_expr_scale, rhs_expr_scale) else: out = _op.add(lhs_expr, rhs_expr) + # for rest inputs + for i in range(len(inputs) - 2): + extra_expr = self.exp_tab.get_expr(inputs[i + 2]) + assert _infer_shape(out) == _infer_shape(extra_expr) + if coeff: + coeff_expr = self.exp_tab.new_const(np.asarray(coeff[i + 2], np.float32)) + extra_expr_scale = _op.multiply(extra_expr, coeff_expr) + out = _op.add(out, extra_expr_scale) + else: + out = _op.add(out, extra_expr) elif eltwise_type_dict[eltwise_type] == "MAX": out = _op.maximum(lhs_expr, rhs_expr) + # for rest inputs + for i in range(len(inputs) - 2): + extra_expr = self.exp_tab.get_expr(inputs[i + 2]) + assert _infer_shape(out) == _infer_shape(extra_expr) + out = _op.maximum(out, extra_expr) else: raise tvm.error.OpNotImplemented( "eltwise_type {} is not supported for frontend Caffe.".format(eltwise_type) diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index 786ea8cb92e0..d2fb8dab644e 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -539,7 +539,45 @@ def test_forward_Eltwise(): operation=1, coeff=[0.5, 1], ) - + _test_eltwise( + [ + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + ], + operation=0, + ) + _test_eltwise( + [ + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + ], + operation=1, + ) + _test_eltwise( + [ + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + ], + operation=2, + ) + _test_eltwise( + [ + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + np.random.rand(1, 3, 10, 11).astype(np.float32), + ], + operation=1, + coeff=[0.5, 1, 0.2, 1.8, 3.1, 0.1], + ) ####################################################################### # Flatten From 368d967c844abc10469fc0d549309df0e6cce071 Mon Sep 17 00:00:00 2001 From: zotanika Date: Wed, 26 May 2021 11:13:54 +0900 Subject: [PATCH 09/14] formatting fix --- tests/python/frontend/caffe/test_forward.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index d2fb8dab644e..3d99ad755a9c 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -579,6 +579,7 @@ def test_forward_Eltwise(): coeff=[0.5, 1, 0.2, 1.8, 3.1, 0.1], ) + ####################################################################### # Flatten # ----------- From 86fea5fcbc707ed35bb3f994743f4a8b7bf6be0d Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 1 Jun 2021 14:37:40 +0900 Subject: [PATCH 10/14] [Caffe Frontend] reverting codes related Reduction for splitting PR --- python/tvm/relay/frontend/caffe.py | 39 ---------- tests/python/frontend/caffe/test_forward.py | 80 --------------------- 2 files changed, 119 deletions(-) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index 4786c4c88759..81c5d1327f4e 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -63,7 +63,6 @@ def __init__(self, init_layer_dict, predict_layer, exp_tab): "Slice": self.convert_slice, "Softmax": self.convert_softmax, "TanH": self.convert_tanh, - "Reduction": self.convert_reduction, } def convert_flatten(self, op): @@ -612,44 +611,6 @@ def convert_tanh(self, op): out = _op.tanh(in_expr) return out - def convert_reduction(self, op): - """ Convert Reduction layer """ - reduction_dic = ["NOP", "SUM", "ASUM", "SUMSQ", "MEAN"] - - inputs = op.bottom - in_expr = self.exp_tab.get_expr(inputs[0]) - method = op.reduction_param.operation - axis = op.reduction_param.axis - coeff = op.reduction_param.coeff - coeff_expr = self.exp_tab.new_const(np.asarray(coeff, np.float32)) - num_axes = len(_infer_shape(in_expr)) - - # Currently, only reduction along ALL "tail" axes is supported in Caffe; - # reduction of axis M through N, where N < num_axes - 1, is unsupported. - if 0 < axis < (num_axes - 1): - for _axis in reversed(range(axis + 1, num_axes)): - in_expr = _op.sum(in_expr, axis=_axis) - in_expr = _op.squeeze(in_expr) - - if reduction_dic[method] == "SUM": - out = _op.sum(in_expr, axis=axis) - elif reduction_dic[method] == "MEAN": - out = _op.mean(in_expr, axis=axis) - elif reduction_dic[method] == "ASUM": - in_expr = _op.abs(in_expr) - out = _op.sum(in_expr, axis=axis) - elif reduction_dic[method] == "SUMSQ": - in_expr = _op.multiply(in_expr, in_expr) - out = _op.sum(in_expr, axis=axis) - else: - raise tvm.error.OpAttributeInvalid( - "reduction method:{} is invalid in Caffe frontend.".format(method) - ) - - if float(coeff) != 1.0: - out = _op.multiply(out, coeff_expr) - return out - def convert_crop(self, op): """ Convert Crop layer """ inputs = op.bottom diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index 786ea8cb92e0..d1396f0435d0 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -790,85 +790,6 @@ def test_forward_TanH(): _test_tanh(np.random.rand(10).astype(np.float32)) -####################################################################### -# Reduction -# ----------- - - -def _test_reduction(data, **kwargs): - """ One iteration of Reduction """ - _test_op(data, L.Reduction, "Reduction", **kwargs) - - -def test_forward_Reduction(): - """ Reduction """ - reduction_op = {"SUM": 1, "ASUM": 2, "SUMSQ": 3, "MEAN": 4} - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0) - _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=3 - ) - _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUM"], axis=1 - ) - _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["SUM"], axis=0, coeff=0.5 - ) - _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), - operation=reduction_op["SUM"], - axis=3, - coeff=5.0, - ) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"]) - _test_reduction( - np.random.rand(10, 20).astype(np.float32), operation=reduction_op["ASUM"], axis=1 - ) - _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["ASUM"], axis=3 - ) - _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["ASUM"], axis=0, coeff=0.0 - ) - _test_reduction( - np.random.rand(10, 20, 30).astype(np.float32), - operation=reduction_op["ASUM"], - axis=2, - coeff=7.0, - ) - _test_reduction( - np.random.rand(10, 20, 30, 40, 10).astype(np.float32), - operation=reduction_op["ASUM"], - axis=3, - coeff=1.0, - ) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0) - _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["SUMSQ"], axis=3 - ) - _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["SUMSQ"], axis=0, coeff=0.0 - ) - _test_reduction( - np.random.rand(10, 20, 30, 40, 50).astype(np.float32), - operation=reduction_op["SUMSQ"], - axis=4, - coeff=2.0, - ) - _test_reduction(np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0) - _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), operation=reduction_op["MEAN"], axis=3 - ) - _test_reduction( - np.random.rand(10).astype(np.float32), operation=reduction_op["MEAN"], axis=0, coeff=0.0 - ) - _test_reduction( - np.random.rand(10, 20, 30, 40).astype(np.float32), - operation=reduction_op["MEAN"], - axis=3, - coeff=2.0, - ) - - ####################################################################### # Mobilenetv2 # ----------- @@ -1013,7 +934,6 @@ def test_forward_Inceptionv1(): # Reshape test_forward_Reshape() test_forward_Flatten() - test_forward_Reduction() # Math test_forward_Concat() From 7aaaaffdf965b28e419c0952be7c69e23ad98982 Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 1 Jun 2021 14:56:52 +0900 Subject: [PATCH 11/14] Revert "[Caffe Frontend] Supporting multiple grouped(channel-wise) Deconv op" This reverts commit 43e25e552b790ce9a38fdbcfb3ddf2075c253e20. --- python/tvm/relay/frontend/caffe.py | 63 ++------------------- tests/python/frontend/caffe/test_forward.py | 27 --------- 2 files changed, 5 insertions(+), 85 deletions(-) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index 1439b1973897..835fbba6ae22 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -530,72 +530,19 @@ def convert_deconv(self, op): if weight: kh, kw = params["kernel_size"] weight_shape = [-1, conv_params.num_output, kh, kw] - if not weight.data: - if conv_params.weight_filler: - _filler = conv_params.weight_filler.value - weight_value = np.full(weight.shape.dim, _filler, np.float32) - else: - raise tvm.error.OpAttributeInvalid("At least weight_filler must be given") - else: - weight_value = np.asarray(weight.data, np.float32) + weight_value = np.asarray(weight.data, np.float32) weight_value = np.reshape(weight_value, weight_shape) else: - raise tvm.error.OpAttributeRequired( - "No weight value of layer {} in caffemodel".format(op.name) - ) + raise Exception("No weight value of layer {} in caffemodel".format(op.name)) weight_expr = self.exp_tab.new_const(weight_value, dtype="float32") in_expr = self.exp_tab.get_expr(inputs[0]) - - groups = params["groups"] - channels = params["channels"] - + out = _op.nn.conv2d_transpose(data=in_expr, weight=weight_expr, **params) if bias: + bias_value = np.asarray(bias.data, np.float32) bias_expr = self.exp_tab.new_const(bias_value, dtype="float32") - - if groups > channels: - raise tvm.error.OpAttributeInvalid( - "Groups cannot be larger than the number of input channels" - ) - - if groups == channels: - inputs_expr = _op.split(in_expr, groups, axis=1) - weights_expr = _op.split(weight_expr, groups, axis=1) - # Preventing to create Concat layer with too many tensors(> 16) - q = groups >> 4 - r = groups % 16 - - params["groups"] = 1 - params["channels"] = 1 - out = [] - for lc in range(q): - _outputs = [] - _inputs = [inputs_expr[i] for i in range(lc << 4, (lc << 4) + 16)] - _weights = [weights_expr[i] for i in range(lc << 4, (lc << 4) + 16)] - for (i, w) in zip(_inputs, _weights): - _out = _op.nn.conv2d_transpose(data=i, weight=w, **params) - if bias: - _out = _op.nn.bias_add(_out, bias_expr) - _outputs.append(_out) - out.append(_op.concatenate(_outputs, axis=1)) - if r != 0: - _outputs = [] - _inputs = [inputs_expr[i] for i in range(groups - r, groups)] - _weights = [weights_expr[i] for i in range(groups - r, groups)] - for (i, w) in zip(_inputs, _weights): - _out = _op.nn.conv2d_transpose(data=i, weight=w, **params) - if bias: - _out = _op.nn.bias_add(_out, bias_expr) - _outputs.append(_out) - out.append(_op.concatenate(_outputs, axis=1)) - out = _op.concatenate(out, axis=1) - elif groups == 1: - out = _op.nn.conv2d_transpose(data=in_expr, weight=weight_expr, **params) - if bias: - out = _op.nn.bias_add(out, bias_expr) - else: - raise tvm.error.OpAttributeInvalid("Unable to handle.") + out = _op.nn.bias_add(out, bias_expr) return out def convert_slice(self, op): diff --git a/tests/python/frontend/caffe/test_forward.py b/tests/python/frontend/caffe/test_forward.py index 50999e336398..0e5ed31d953d 100644 --- a/tests/python/frontend/caffe/test_forward.py +++ b/tests/python/frontend/caffe/test_forward.py @@ -452,33 +452,6 @@ def test_forward_Deconvolution(): bias_filler=dict(type="xavier"), ), ) - _test_deconvolution( - data, - convolution_param=dict( - num_output=16, - bias_term=False, - pad=0, - kernel_size=2, - stride=2, - dilation=1, - group=16, - weight_filler=dict(type="xavier"), - bias_filler=dict(type="xavier"), - ), - ) - data = np.random.rand(1, 100, 32, 32).astype(np.float32) - _test_deconvolution( - data, - convolution_param=dict( - num_output=100, - bias_term=False, - pad=0, - kernel_size=2, - stride=2, - dilation=1, - group=100, - ), - ) ####################################################################### From 5fd84865e85623a9bb8faf82fe8677ab669b22f1 Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 1 Jun 2021 15:34:43 +0900 Subject: [PATCH 12/14] instant fix against docker format error --- python/tvm/driver/tvmc/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/driver/tvmc/compiler.py b/python/tvm/driver/tvmc/compiler.py index dcb770b9a563..43a841cc8e15 100644 --- a/python/tvm/driver/tvmc/compiler.py +++ b/python/tvm/driver/tvmc/compiler.py @@ -38,7 +38,7 @@ @register_parser def add_compile_parser(subparsers): - """ Include parser for 'compile' subcommand """ + """Include parser for 'compile' subcommand""" parser = subparsers.add_parser("compile", help="compile a model") parser.set_defaults(func=drive_compile) From 9321a2010fe45e79fa978bef740fcad13c10bb5f Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 1 Jun 2021 15:53:48 +0900 Subject: [PATCH 13/14] instant fix against docker format error --- python/tvm/relay/frontend/caffe.py | 44 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index 835fbba6ae22..adbb77a508f0 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -33,7 +33,7 @@ class OperatorConverter(object): - """ Operator Converted for converting Caffe ops to Relay ops """ + """Operator Converted for converting Caffe ops to Relay ops""" def __init__(self, init_layer_dict, predict_layer, exp_tab): self.init_layer_dict = init_layer_dict @@ -66,7 +66,7 @@ def __init__(self, init_layer_dict, predict_layer, exp_tab): } def convert_flatten(self, op): - """ Convert Flatten layer """ + """Convert Flatten layer""" inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) @@ -77,7 +77,7 @@ def convert_flatten(self, op): return out def convert_eltwise(self, op): - """ Convert Eltwise layer """ + """Convert Eltwise layer""" inputs = op.bottom assert len(inputs) >= 2, "input tensors length should be larger than 2" @@ -134,7 +134,7 @@ def convert_eltwise(self, op): return out def _parse_conv_params(self, op): - """ Parse the parameters of Convolution and Deconvolution layer """ + """Parse the parameters of Convolution and Deconvolution layer""" nonzone = lambda val, pos, dflt: val[pos] if pos < len(val) else dflt conv_params = op.convolution_param @@ -179,7 +179,7 @@ def _parse_conv_params(self, op): return params def convert_batch_norm(self, op): - """ Convert BatchNorm layer """ + """Convert BatchNorm layer""" inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) n, c, h, w = _infer_shape(in_expr) @@ -234,7 +234,7 @@ def convert_batch_norm(self, op): return out[0] def convert_scale(self, op): - """ Convert Scale layer """ + """Convert Scale layer""" inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) weight_bias_blobs = self.init_layer_dict[op.name].blobs @@ -262,7 +262,7 @@ def convert_scale(self, op): return out def convert_concat(self, op): - """ Convert Concat layer """ + """Convert Concat layer""" inputs = op.bottom in_expr = (self.exp_tab.get_expr(inputs[i]) for i in range(len(inputs))) @@ -313,7 +313,7 @@ def convert_reshape(self, op): return out def convert_softmax(self, op): - """ Convert Softmax layer """ + """Convert Softmax layer""" inputs = op.bottom assert len(inputs) == 1, "input tensors length should be 1" @@ -328,7 +328,7 @@ def convert_softmax(self, op): return out def convert_conv(self, op): - """ Convert Convolution layer """ + """Convert Convolution layer""" params = self._parse_conv_params(op) weight_bias_blobs = self.init_layer_dict[op.name].blobs conv_params = op.convolution_param @@ -358,7 +358,7 @@ def convert_conv(self, op): return out def convert_pooling(self, op): - """ Convert Pooling layer """ + """Convert Pooling layer""" inputs = op.bottom input_name = inputs[0] @@ -419,7 +419,7 @@ def convert_pooling(self, op): return out def convert_lrn(self, op): - """ Convert LRN layer """ + """Convert LRN layer""" inputs = op.bottom input_name = inputs[0] @@ -435,7 +435,7 @@ def convert_lrn(self, op): return out def convert_innerproduct(self, op): - """ Convert InnerProduct layer """ + """Convert InnerProduct layer""" inputs = op.bottom weight_bias_blobs = self.init_layer_dict[op.name].blobs dense_params = op.inner_product_param @@ -476,7 +476,7 @@ def convert_innerproduct(self, op): return out def convert_dropout(self, op): - """ Convert Dropout layer """ + """Convert Dropout layer""" inputs = op.bottom input_name = inputs[0] @@ -490,7 +490,7 @@ def convert_dropout(self, op): return out def convert_relu(self, op): - """ Convert ReLU layer """ + """Convert ReLU layer""" inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) negative_slope = op.relu_param.negative_slope @@ -502,7 +502,7 @@ def convert_relu(self, op): return out def convert_prelu(self, op): - """ Convert PReLU layer """ + """Convert PReLU layer""" inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) @@ -514,7 +514,7 @@ def convert_prelu(self, op): return out def convert_deconv(self, op): - """ Convert Deconvolution layer """ + """Convert Deconvolution layer""" params = self._parse_conv_params(op) weight_bias_blobs = self.init_layer_dict[op.name].blobs conv_params = op.convolution_param @@ -546,7 +546,7 @@ def convert_deconv(self, op): return out def convert_slice(self, op): - """ Convert Slice layer """ + """Convert Slice layer""" inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) @@ -564,21 +564,21 @@ def convert_slice(self, op): return out def convert_sigmoid(self, op): - """ Convert Sigmoid layer """ + """Convert Sigmoid layer""" inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) out = _op.sigmoid(in_expr) return out def convert_tanh(self, op): - """ Convert TanH layer """ + """Convert TanH layer""" inputs = op.bottom in_expr = self.exp_tab.get_expr(inputs[0]) out = _op.tanh(in_expr) return out def convert_crop(self, op): - """ Convert Crop layer """ + """Convert Crop layer""" inputs = op.bottom assert len(inputs) == 2, "Need two inputs of Crop layer" in_expr_a = self.exp_tab.get_expr(inputs[0]) @@ -634,7 +634,7 @@ def check_unsupported_ops(self): raise tvm.error.OpNotImplemented(msg.format(ops)) def fuse_op(self, layers): - """ Fusing the BatchNorm and Scale layer """ + """Fusing the BatchNorm and Scale layer""" bn, scale = layers["bn"], layers["scale"] # bn params @@ -660,7 +660,7 @@ def fuse_op(self, layers): return bn def op_fuse(self): - """fuse bn and scale """ + """fuse bn and scale""" new_layers = [] temp_layers = {} changed_layers = {} From e12a010db640f03fd02414fae47326b27743689b Mon Sep 17 00:00:00 2001 From: zotanika Date: Tue, 1 Jun 2021 16:11:39 +0900 Subject: [PATCH 14/14] instant fix against docker format error --- python/tvm/relay/frontend/caffe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/caffe.py b/python/tvm/relay/frontend/caffe.py index adbb77a508f0..390369f7a26d 100644 --- a/python/tvm/relay/frontend/caffe.py +++ b/python/tvm/relay/frontend/caffe.py @@ -273,7 +273,7 @@ def convert_concat(self, op): return out def convert_reshape(self, op): - """ Convert Reshape layer """ + """Convert Reshape layer""" inputs = op.bottom input_name = inputs[0]