Skip to content

[TOPI] LRN & L2norm Operator - #1000

Closed
PariksheetPinjari909 wants to merge 0 commit into
apache:masterfrom
PariksheetPinjari909:master
Closed

[TOPI] LRN & L2norm Operator#1000
PariksheetPinjari909 wants to merge 0 commit into
apache:masterfrom
PariksheetPinjari909:master

Conversation

@PariksheetPinjari909

Copy link
Copy Markdown
Contributor

LRN operator for caffe alexnet model to use with onnx frontend

@PariksheetPinjari909PariksheetPinjari909 changed the title LRN Operator[WIP]LRN OperatorMar 13, 2018
@PariksheetPinjari909PariksheetPinjari909 changed the title [WIP]LRN OperatorLRN OperatorMar 14, 2018
@tqchen

Copy link
Copy Markdown
Member

@sxjscience can you help review this?

@tqchen
tqchen requested a review from sxjscienceMarch 15, 2018 02:18
@tqchentqchen changed the title LRN Operator[TOPI] LRN OperatorMar 15, 2018
@sxjscience

Copy link
Copy Markdown
Member

I'll check the formula next week... This week I decide to focus on the MT demo.

@sxjscience

Copy link
Copy Markdown
Member

Looks that the functionality can be implemented by stacking multiple reduce/broadcast ops in TOPI.

@PariksheetPinjari909

Copy link
Copy Markdown
ContributorAuthor

@sxjscience Using broadcast/reduce I feel it will be difficult since we need to compute for a selected area based on the "local size" parameter, thats why i used reduce_axis to do the sum operation. Can you give a reference how to use broadcast/reduce operator in this scenario?

@sxjscience

sxjscience commented Mar 19, 2018 via email

Copy link
Copy Markdown
Member

@PariksheetPinjari909

Copy link
Copy Markdown
ContributorAuthor

I will upload L2norm operator implementation also along with this pull request, please help to review together.

@PariksheetPinjari909PariksheetPinjari909 changed the title [TOPI] LRN Operator[TOPI] LRN & L2norm OperatorMar 19, 2018
@tqchen

Copy link
Copy Markdown
Member

ping @sxjscience can you take another look

Comment threadtopi/python/topi/nn/l2_norm.py Outdated
import tvm

@tvm.target.generic_func
def l2norm_instance_nchw(data, eps):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should implement L2Norm with arbitrary shape and axis.


##Add padding on left & right of size radius first
pad_before = [0, int(size/2), 0, 0]
pad_after = [0, int(size/2), 0, 0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use size // 2 instead of int(size/2)

rxk = tvm.reduce_axis((0, size), name='rxk')
sqr_sum = tvm.compute((b, c, h, w), lambda i, l, j, k: tvm.sum(
pad_data[i, l + rxk, j, k] * pad_data[i, l + rxk, j, k],
axis=rxk))

@sxjsciencesxjscienceMar 25, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can first use square and then use topi.sum, for example: I've misunderstood the code. We cannot do this.

lrn_out[i, c, j, k] = a_np[i, c, j, k] / \
sqr_sum_up[i, c, j, k]

return lrn_out

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move the python implementation to test_topi_lrn.py.

Comment threadtopi/tests/python/test_topi_lrn.py Outdated
b = tvm.nd.array(np.zeros(get_const_tuple(B.shape), dtype=dtype), ctx)
f = tvm.build(s, [A, B], device)
f(a, b)
np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-1)

@sxjsciencesxjscienceMar 25, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that rtol=1e-1 is too loose. We should set it to a smaller value like 1E-4 or 1E-3.

Comment threadtopi/python/topi/nn/l2_norm.py Outdated

@tvm.target.generic_func
def l2norm_instance_nchw(data, eps):
"""Perform local response normalisation on the data

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is L2Norm instead of local response normalization.


@tvm.target.generic_func
def lrn_nchw(data, size, alpha=0.0001, beta=0.75, bias=2):
"""Perform local response normalisation on the data

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(bias + (alpha * sqr_sum[i, j, k, l] / size)), beta))

return tvm.compute(data.shape,
lambda b, c, h, w: data[b, c, h, w] / sqr_sum_up[b, c, h, w])

@sxjsciencesxjscienceMar 25, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can reuse the implemented binary broadcasting operators like topi.broadcast_div.

@PariksheetPinjari909

PariksheetPinjari909 commented Mar 26, 2018

Copy link
Copy Markdown
ContributorAuthor

@tqchen can you please reopen this PR, i accidentally closed it.

@PariksheetPinjari909

Copy link
Copy Markdown
ContributorAuthor

Review comments are updated in #1051

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@PariksheetPinjari909@tqchen@sxjscience