-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Caffe Frontend] adding Reduction op #8015
Conversation
cc @jcf94 @kazum @FrozenGene please help to manage this PR. Thank you! |
@@ -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"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find logic code to handle NOP
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOP
was placed in reduction_dic to remind users(and me) of the attribution of Caffe Reduction op, default operation SUM
is starting from 1; https://caffe.berkeleyvision.org/tutorial/layers/reduction.html.
If warning against the wrong attribution 0 is considered redundant, I'll remove it..
python/tvm/relay/frontend/caffe.py
Outdated
"reduction method:{} is invalid in Caffe frontend.".format(method) | ||
) | ||
|
||
out = _op.multiply(out, coeff_expr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could do a little optimization for this. For example, if coeff_expr
is not 1
, we call multiply
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this suggestion is included in new commit.
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.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us add more values for axis
and coeff
to cover more conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this suggestion is included in new commit. some more codes were introduced to handle reductions on non-tail axis and give back the result equivalent to Caffe framework.
- 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 <[email protected]>
@FrozenGene Please take another look :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitty comment.
@zotanika please resolve the conflict. |
* [Caffe Frontend] adding Reduction op * reformatting Reduction op test script * reformatting Reduction test script * [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 <[email protected]> * linting test script * linting * typo fix Co-authored-by: sunchul.jung <[email protected]>
* [Caffe Frontend] adding Reduction op * reformatting Reduction op test script * reformatting Reduction test script * [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 <[email protected]> * linting test script * linting * typo fix Co-authored-by: sunchul.jung <[email protected]>
* [Caffe Frontend] adding Reduction op * reformatting Reduction op test script * reformatting Reduction test script * [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 <[email protected]> * linting test script * linting * typo fix Co-authored-by: sunchul.jung <[email protected]>
Reduction op for Caffe frontend, supporting SUM, ASUM, SUMSQ, MEAN methods.