Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webnn] Add float32 tests for resample2d (downsample) #45017

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BruceDai
Copy link
Contributor

@BruceDai BruceDai commented Mar 11, 2024

This PR is split from #41811, let's keep this one for further investigation and discussion.

Move last discussion on #41811 here.

@fdwr This PR is to add 13 float32 resample2d tests. I ran these tests by internal Chromium build using WebNN DirectML backend, got 10 PASS and 3 FAIL. image

These 3 FAIL tests are all for resample(down sampling) on "nearest-neighbor" mode with below 4D input of shape [1, 1, 4, 6]

// nchw layout
[[[[ 3.86005284, 45.18463077, 87.67153743, 98.78210347, 66.37414347,  3.41158349],
   [86.14930501, 95.9813372 , 76.87126314, 16.52591355, 65.98782867, 25.47092156],
   [22.56010548, 92.08479613, 85.80876635, 92.63166027, 29.91620871, 75.40461275],
   [62.06375451,  1.77121588, 99.47231285, 11.44055014, 25.39634271, 67.02175102]]]]

by options.sizes = [2, 3] or options.scales = [0.5, 0.5],

output is of shape [1, 1, 2, 3] and its actual value as below

// using bottom right data
[[[[95.9813372 , 16.52591355, 25.47092156],
   [ 1.77121588, 11.44055014, 67.02175102]]]]

while our expected data were generated by https://github.com/webmachinelearning/webnn-baseline/blob/main/src/resample2d.js with same input data and options:

// using top left data
[[[[ 3.86005284, 87.67153743, 66.37414347],
   [22.56010548, 85.80876635, 29.916208715]]]]

I'm not sure which is wrong on

  1. Pure JavaScripts reampled2d implementation for WebNN Baseline
  2. Chromium implementation for reampled2d on DirectML backend

Do you have any ideas? Thanks.

And @fdwr commented

I'm not sure which is wrong on

Both are reasonable and not really "wrong" - we just have to pick one. The only truly wrong ones are those libraries that always floor pixels (broken libraries) which result in shifted images, but I believe most image resampling API's round input coordinate on halves toward negative infinity, and ONNX's Resize defaults nearest_mode to round_prefer_floor.

This is easy to control via DML_RESAMPLE2_OPERATOR_DESC in Feature Level 5.1 with the RoundingDirection (used here in the ORT DML EP), but I'm concerned how to achieve it with the older RESAMPLE1 🤔, as my previous comment in the ORT DML EP said that "round_prefer_floor" could not be achieved without an API update. The older function used floor(input.x + 0.5), but that's effectively rounding halves up! ⏳...

Copy link

@fdwr fdwr left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants