Repository navigation
Fix CropAndResize op - #21660
Fix CropAndResize op#21660dkurt wants to merge 4 commits into
Conversation
|
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. What to do if you already signed the CLAIndividual signers
Corporate signers
|
|
Thanks @dkurt for the PR. Could you fill out the cla? |
|
@yifeif, sure. Please do not merge it immediately because I wanted to add a test. |
|
CLAs look good, thanks! |
|
I signed it! |
|
Thanks for filling the CLA @dkurt! Let us know when this is ready for review. |
|
@yifeif, it's ready to be reviewed. Thanks! |
|
@jch1 do you mind taking a look? Thanks! |
a4e126f to
7bc90f9
Compare
penpornk
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
This will not work correctly if in_y is an integer, i.e., in_y == top_y_index == bottom_y_index.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
Modified it. Let's check the test.
There was a problem hiding this comment.
Thanks for the clarification!
I reran the tests. 9 of them failed.
6df522a to
83a78ba
Compare
penpornk
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
Box indices array is one-dimensional.
| 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}); |
There was a problem hiding this comment.
This line is probably too long. Please apply clang-format.
|
@dkurt are you planning to address reviewer comments ? |
|
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! |
Prevent floating point arithmetic influence on CropAndResize op