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

Add Gluon Transformer Crop #14259

Merged
merged 13 commits into from
Apr 3, 2019

Conversation

stu1130
Copy link
Contributor

@stu1130 stu1130 commented Feb 26, 2019

Description

  • Add crop operator and gluon transformer front
  • support batch input
  • modify the fixed_crop with slice

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

Comments

@zhreshold

@stu1130 stu1130 requested a review from szha as a code owner February 26, 2019 23:23
@anirudhacharya
Copy link
Member

@mxnet-label-bot add [pr-awaiting-review]

@stu1130 is this trying to achieve the same functionality as this PR - #13679

have the comments in the previous PR( 1 and 2) been addressed here? could you please elaborate on how the comments have been addressed in this new PR?

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Feb 27, 2019
@stu1130
Copy link
Contributor Author

stu1130 commented Feb 27, 2019

@anirudhacharya yes it is
For the first one, the resize functionality is moved out of Crop operator so no .value() is needed. And I added the usage and doc for it.
For the second one, if we want to make fixed_crop take advantage of my operator ,it would be one line change from using the nd.crop to nd.image.crop. Nothing sinificant change. so I kept the original one.

@azai91
Copy link
Contributor

azai91 commented Feb 27, 2019

what is the behavior if the crop size is greater than the input image for either dimension?

@stu1130
Copy link
Contributor Author

stu1130 commented Feb 27, 2019

@azai91
Copy link
Contributor

azai91 commented Feb 27, 2019

got it, thanks

@@ -228,6 +228,54 @@ def forward(self, x):
return image.random_size_crop(x, *self._args)[0]


class Crop(HybridBlock):
Copy link
Member

Choose a reason for hiding this comment

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

there is an deprecated mx.sym.Crop op already, using sym.image.Crop may introduce some confusion again, can you propose a new name?

For image transformation, since resize is supported, I guess CropResize is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you intend to expand the implementation to add more parameters like x1, y1 ? If so then it makes sense to keep them x0 and y0. Else I think you should change them to x and y

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @access2rohit I assume now I only need one x and y so I'll go with x and y

Makes a crop of the original image then optionally resize it to the specified size.
Parameters
----------
x0 : int
Copy link
Member

Choose a reason for hiding this comment

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

imo, x is better than x0 since there is nox1

----------
x0 : int
Left boundary of the cropping area
y0 : int
Copy link
Member

Choose a reason for hiding this comment

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

same here

.set_attr<nnvm::FInferShape>("FInferShape", CropShape)
.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
.set_attr<FCompute>("FCompute<cpu>", Crop)
.set_attr<nnvm::FGradient>("FGradient", ElemwiseGradUseNone{ "_copy" })
Copy link
Member

Choose a reason for hiding this comment

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

copy gradient does not apply to crop op.


def hybrid_forward(self, F, x):
out = F.image.crop(x, self._x0, self._y0, self._width, self._height)
if self._size is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

if self._size

DMLC_DECLARE_FIELD(width)
.describe("Width of the cropping area.");
DMLC_DECLARE_FIELD(height)
.describe("Top boundary of the cropping area");
Copy link
Contributor

Choose a reason for hiding this comment

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

Height of the cropping area?

@stu1130
Copy link
Contributor Author

stu1130 commented Mar 15, 2019

@zhreshold ready for 2nd round review. Thanks

Copy link
Member

@zhreshold zhreshold 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 addressing previous comments, I see no issue, but can you add unittest for backward gradient check?

@stu1130
Copy link
Contributor Author

stu1130 commented Apr 2, 2019

@zhreshold I added the unit test for backward gradient check

Copy link
Contributor

@sandeep-krishnamurthy sandeep-krishnamurthy left a comment

Choose a reason for hiding this comment

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

Thanks. Few minor comments.

python/mxnet/gluon/data/vision/transforms.py Outdated Show resolved Hide resolved
python/mxnet/gluon/data/vision/transforms.py Outdated Show resolved Hide resolved
src/operator/image/crop-inl.h Outdated Show resolved Hide resolved
src/operator/image/crop-inl.h Show resolved Hide resolved
src/operator/image/crop-inl.h Outdated Show resolved Hide resolved
Copy link
Contributor

@sandeep-krishnamurthy sandeep-krishnamurthy left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks

@sandeep-krishnamurthy sandeep-krishnamurthy added pr-awaiting-merge Review and CI is complete. Ready to Merge and removed pr-awaiting-review PR is waiting for code review labels Apr 3, 2019
@sandeep-krishnamurthy sandeep-krishnamurthy merged commit 5241c1b into apache:master Apr 3, 2019
nswamy pushed a commit that referenced this pull request Apr 5, 2019
* implement crop

* add crop operator

* fix for linter

* add. backword and refactor the code

* fix error namespace

* fix the website build failure

* start adding the unit test of backword

* add unit test for backward

* address the comment

* add missing statement

* fix the website error

* fix the website building

* add missing doc
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
* implement crop

* add crop operator

* fix for linter

* add. backword and refactor the code

* fix error namespace

* fix the website build failure

* start adding the unit test of backword

* add unit test for backward

* address the comment

* add missing statement

* fix the website error

* fix the website building

* add missing doc
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

8 participants