Skip to content

Fix CropAndResize op - #21660

Closed
dkurt wants to merge 4 commits into
tensorflow:masterfrom
dkurt:fix_crop_and_resize
Closed

dkurt wants to merge 4 commits into
tensorflow:masterfrom
dkurt:fix_crop_and_resize

Conversation

@dkurt

@dkurt dkurt commented Aug 16, 2018

Copy link
Copy Markdown

Prevent floating point arithmetic influence on CropAndResize op

@googlebot

Copy link
Copy Markdown

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@yifeif yifeif self-assigned this Aug 16, 2018
@yifeif

yifeif commented Aug 16, 2018

Copy link
Copy Markdown
Contributor

Thanks @dkurt for the PR. Could you fill out the cla?

@dkurt

dkurt commented Aug 16, 2018

Copy link
Copy Markdown
Author

@yifeif, sure. Please do not merge it immediately because I wanted to add a test.

@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

@dkurt

dkurt commented Aug 16, 2018

Copy link
Copy Markdown
Author

I signed it!

@yifeif

yifeif commented Aug 17, 2018

Copy link
Copy Markdown
Contributor

Thanks for filling the CLA @dkurt! Let us know when this is ready for review.

@dkurt

dkurt commented Aug 18, 2018

Copy link
Copy Markdown
Author

@yifeif, it's ready to be reviewed. Thanks!

@yifeif

yifeif commented Nov 20, 2018

Copy link
Copy Markdown
Contributor

@jch1 do you mind taking a look? Thanks!

@yifeif yifeif added the ready to pull PR ready for merge process label Dec 5, 2018
@rthadur rthadur added the size:S CL Change Size: Small label Jan 2, 2019
@rthadur rthadur assigned rthadur and unassigned yifeif Apr 4, 2019
@rthadur
rthadur requested review from penpornk and removed request for jch1 April 4, 2019 22:52
@dkurt
dkurt force-pushed the fix_crop_and_resize branch from a4e126f to 7bc90f9 Compare April 5, 2019 13:42
@penpornk penpornk added the kokoro:force-run Tests on submitted change label Apr 9, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Apr 9, 2019
kyscg
kyscg previously approved these changes Apr 16, 2019
@penpornk penpornk added kokoro:force-run Tests on submitted change and removed ready to pull PR ready for merge process labels Apr 16, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Apr 16, 2019

@penpornk penpornk left a comment

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'm so sorry for our delay! Thank you for your patience!

  • I think there are build errors. Please check the failing tests, especially Ubuntu CC.
  • Could you please explain what is wrong with the original code?

if (method_name == "bilinear") {
const int top_y_index = floorf(in_y);
const int bottom_y_index = ceilf(in_y);
const int bottom_y_index = std::min(top_y_index + 1, image_height - 1);

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 will not work correctly if in_y is an integer, i.e., in_y == top_y_index == bottom_y_index.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@penpornk, Thanks for review! Al this PR is driven by specific test case (see changed file). As far as I remember, without the changes in CropAndResize op it had last line with zeros.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Modified it. Let's check the test.

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.

Thanks for the clarification!
I reran the tests. 9 of them failed.

@dkurt
dkurt force-pushed the fix_crop_and_resize branch from 6df522a to 83a78ba Compare April 16, 2019 17:28
@penpornk penpornk added the kokoro:force-run Tests on submitted change label Apr 16, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Apr 16, 2019

@penpornk penpornk left a comment

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.

Got it! Thank you very much for the quick explanation and fixes! I think there is still some problems with the logic.

: 0.5 * (y1 + y2) * (image_height - 1);
if (in_y < 0 || in_y > image_height - 1) {
const int top_y_index = floorf(in_y);
if (top_y_index < 0 || top_y_index > image_height - 1) {

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.

Some in_y that should be using the extrapolation_value (image_height-1 < in_y < image_height) can skip this loop and cause index-out-of-bound accesses during the bilinear interpolation, e.g., image(b_in, bottom_y_index, left_x_index, d) -> image(b_in, image_height, left_x_index, d).

I think we should just check on the box boundaries in addition to the original in_y check. For example, don't pad when boundaries are in range [0, 1]. Will probably need to add code to handle index-out-of-bound because of floating-point errors as well. (For example, when in_y == image_height - 1 + epsilon when it should be just image_height-1.)

// Box:
// 0.095093 0.024008 1.000000 1.000000
AddInputFromArray<float>(TensorShape({1, 4}), {0x1.858054p-4, 0x1.8957d6p-6, 1.0f, 1.0f});
AddInputFromArray<int32>(TensorShape({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.

Box indices array is one-dimensional.

Suggested change
AddInputFromArray<int32>(TensorShape({2}), {0, 0});
AddInputFromArray<int32>(TensorShape({1}), {0});

{1, 2, 3, 4, 5, 6, 7, 8, 9});
// Box:
// 0.095093 0.024008 1.000000 1.000000
AddInputFromArray<float>(TensorShape({1, 4}), {0x1.858054p-4, 0x1.8957d6p-6, 1.0f, 1.0f});

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 line is probably too long. Please apply clang-format.

@rthadur

rthadur commented Jun 18, 2019

Copy link
Copy Markdown
Contributor

@dkurt are you planning to address reviewer comments ?

@rthadur

rthadur commented Jun 26, 2019

Copy link
Copy Markdown
Contributor

I'm going to go ahead and close this PR, because it seems to have stalled. If you're still interested in pursing this (and responding to my comments), please feel free to reopen!

@rthadur rthadur closed this Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes size:S CL Change Size: Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants