zotanika commented on a change in pull request #8015:
URL: https://github.com/apache/tvm/pull/8015#discussion_r634073556
##########
File path: python/tvm/relay/frontend/caffe.py
##########
@@ -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)
Review comment:
this suggestion is included in new commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]