Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[Done] BilinearResize2D optimized #16292

Merged
merged 17 commits into from
Nov 12, 2019
Merged

[Done] BilinearResize2D optimized #16292

merged 17 commits into from
Nov 12, 2019

Conversation

chinakook
Copy link
Contributor

@chinakook chinakook commented Sep 27, 2019

Description

  1. align_corners param in resize op is first introduced by ten*low, then py*ch also bring it to its interpolate op. Our mx.nd.contrib.BilinearResize2D op only support align_corners=True before. Now, We bring align_corners=False(same as OpenCV resize in LINEAR mode) support as sometimes it will get more efficient.
  2. Optimize the performance of foreward and backward of mx.nd.contrib.BilinearResize2D.
  3. Optimize the performance of mx.nd.contrib.BilinearResize2D in fp16 as it is too slow before. As I've tested, If we explictly set dtype to float16, we can speed up our training when compared to float32. So we can speed up the training of gluoncv segmentation models later.
  4. Fix the nd.image.resize op, keep it consistent in CPU and GPU
  5. Remove the consistency tests in test_gluon_transforms.py as it's not right.
    img

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http:https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@marcoabreu
Copy link
Contributor

Test? :)

@chinakook
Copy link
Contributor Author

Yes, I've tested compared to interpolate of py*ch and It works good. There are no enough test cases of this op, should we add?

@marcoabreu
Copy link
Contributor

Yeah, it would be great if you could add testcases

add BilinearResize2D test

fix BilinearResize2D align_corners test

fix code layout

fix resize gpu and cpu consistency

fix bilinear reisze test bug

close transforms.resize test
@chinakook chinakook changed the title Add align_corners parameter to bilinear resize op. BilinearResize2D optimizeed Sep 30, 2019
@chinakook chinakook changed the title BilinearResize2D optimizeed [WIP] BilinearResize2D optimized Sep 30, 2019
@chinakook chinakook changed the title [WIP] BilinearResize2D optimized [Done] BilinearResize2D optimized Oct 3, 2019
@chinakook
Copy link
Contributor Author

@wkcn @zhanghang1989 @marcoabreu for review

Copy link
Member

@wkcn wkcn left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!
If there is some code reference, please add the note which part is Adapted from xxx and its link, like https://github.com/apache/incubator-mxnet/blob/master/src/operator/pad.cc#L34.

Thx!

src/operator/contrib/bilinear_resize-inl.cuh Outdated Show resolved Hide resolved
src/operator/contrib/bilinear_resize-inl.cuh Outdated Show resolved Hide resolved
@@ -65,7 +65,7 @@ void ResizeImplCUDA(mshadow::Stream<gpu> *s,
cudaStream_t stream = mshadow::Stream<gpu>::GetStream(s);
caffe_gpu_interp2_kernel<gpu, DType, AccReal>
<<<blocks, threads , 0, stream>>>(
num_kernels, rheight, rwidth, input, output, layout);
num_kernels, rheight, rwidth, /*align_corners=*/false, input, output);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove commented out code

@@ -146,12 +146,16 @@ def py_bilinear_resize_nhwc(x, outputHeight, outputWidth):
w1lambda*x[b][h1+h1p][w1+w1p][c])
return y

# TODO: close tests below, because `transforms.Resize` use BilinearResize2D(with align_corners=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove them then and put the reason into the PR description

src/operator/contrib/bilinear_resize-inl.cuh Outdated Show resolved Hide resolved
src/operator/contrib/bilinear_resize-inl.cuh Outdated Show resolved Hide resolved
src/operator/contrib/bilinear_resize-inl.cuh Show resolved Hide resolved
src/operator/contrib/bilinear_resize-inl.h Outdated Show resolved Hide resolved
src/operator/contrib/bilinear_resize-inl.cuh Outdated Show resolved Hide resolved
src/operator/contrib/bilinear_resize.cc Outdated Show resolved Hide resolved
src/operator/contrib/bilinear_resize.cc Outdated Show resolved Hide resolved
@chinakook
Copy link
Contributor Author

@wkcn It's all resolved, can we merge this?

Copy link
Member

@wkcn wkcn left a comment

Choose a reason for hiding this comment

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

Thank you for the great contribution!

LGTM : )

tests/python/gpu/test_gluon_transforms.py Show resolved Hide resolved
@wkcn wkcn added the pr-awaiting-merge Review and CI is complete. Ready to Merge label Nov 12, 2019
@wkcn wkcn removed the pr-awaiting-merge Review and CI is complete. Ready to Merge label Nov 12, 2019
@wkcn wkcn added the pr-awaiting-merge Review and CI is complete. Ready to Merge label Nov 12, 2019
@wkcn wkcn merged commit 3885bbe into apache:master Nov 12, 2019
@wkcn
Copy link
Member

wkcn commented Nov 12, 2019

Merged. Thanks for your great contribution!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-merge Review and CI is complete. Ready to Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants