-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Fix documentation for bilinear upsampling and add unit test #14035
Conversation
@mxnet-label-bot add [pr-work-in-progress, Operator] |
@apeforest @anirudh2290 can you please help review? |
src/operator/nn/upsampling-inl.h
Outdated
.set_default(0); | ||
DMLC_DECLARE_FIELD(sample_type) | ||
.add_enum("nearest", up_enum::kNearest) | ||
.add_enum("bilinear", up_enum::kBilinear) | ||
.describe("upsampling method"); | ||
DMLC_DECLARE_FIELD(num_args).set_default(1) |
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.
why are we changing set_lower_bound
to set_default
. This is for proper error messaging when user provides bad inputs.
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.
missed changing this back. will do that
python/mxnet/base.py
Outdated
@@ -483,8 +483,6 @@ def build_param_doc(arg_names, arg_types, arg_descs, remove_dup=True): | |||
for key, type_info, desc in zip(arg_names, arg_types, arg_descs): | |||
if key in param_keys and remove_dup: | |||
continue | |||
if key == 'num_args': |
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.
num_args is populated for variable length inputs without users having to worry about it. If we remove this the additional num_args field can confuse users.
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.
ok, then i'll just add a note in the description about providing 2 inputs for bilinear sampling
src/operator/nn/upsampling-inl.h
Outdated
.describe("Number of inputs to be upsampled. For nearest neighbor " | ||
"upsampling, this can be 1-N; the size of output will be" | ||
"(scale*h_0,scale*w_0) and all other inputs will be upsampled to the" | ||
"same size. For bilinear upsampling this must be 2; 1 input and 1 weight."); |
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.
We can just move this information to the description of data field.
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.
ok
@@ -1514,6 +1527,20 @@ def test_nearest_upsampling(): | |||
check_nearest_upsampling_with_shape(shapes, scale, root_scale) | |||
|
|||
|
|||
@with_seed() | |||
def test_bilinear_upsampling(): | |||
for root_scale in [2,3]: |
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.
you could use itertools.product
like here - https://github.com/anirudhacharya/incubator-mxnet/blob/master/tests/python/unittest/test_optimizer.py#L1225
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.
ok
arr_grad = {'arg_%d'%i: mx.nd.zeros(shape) for i, shape in zip(range(len(shapes)), shapes)} | ||
|
||
up = mx.sym.UpSampling(*[mx.sym.Variable('arg_%d'%i) for i in range(len(shapes))], sample_type='bilinear', scale=root_scale) | ||
def check_bilinear_upsampling_with_shape(data_shape, weight_shape, scale, root_scale, num_filter): |
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.
Why did you change the unit test if your PR is to fix documentation?
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.
@apeforest the unit test was not being called previously. And based on inputs from the issues in Ref section of the PR description, many users are confused about how to use the Upsampling operator with the bilinear upsampling option. So i thought I could add/modify tests here as well - which would show how to use the operator.
I have updated the PR title - should I open a separate PR instead?
Note: This PR is WIP as an assert has to be added at the end of the test. Based on an offline discussion with @anirudh2290 yesterday, the assert will be similar to what was done for test_deconvolution()
@mxnet-label-bot update [Operator, pr-awaiting-review] |
@apeforest @anirudhacharya Are you comments on the PR addressed now ? Can this PR be taken forward now ? |
@anirudh2290 @apeforest Can you take another look at this PR? |
…4035) * Bilinear upsampling documentation and test * test trial * Edit test * Addressed review comments * Fix lint error * Test target shape
…4035) * Bilinear upsampling documentation and test * test trial * Edit test * Addressed review comments * Fix lint error * Test target shape
Description
Fixes #13078
Future work/alternate approaches:
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments
Ref:
#9138
https://stackoverflow.com/questions/47897924/implementing-bilinear-interpolation-with-mxnet-ndarray-upsampling
#12970
#12983
#1412
https://discuss.mxnet.io/t/use-mx-nd-upsampling-with-bilinear-sample-type/2067/2