Bugfix: Updated the step of calculating output sizes by scales for resample2d#611
Conversation
|
@huningxin @fdwr @lisa0314 PTAL, thanks. |
index.bs
Outdated
| 1. If |options|.{{MLResample2dOptions/sizes}} [=map/exists=], set |desc|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] to |options|.{{MLResample2dOptions/sizes}}[|index|] and return |desc|. | ||
| 1. Otherwise, set |desc|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] to |input|'s [=MLOperand/shape=][|index|] multiplied by |options|.{{MLResample2dOptions/scales}}. | ||
| 1. If |options|.{{MLResample2dOptions/sizes}} [=map/exists=], set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |options|.{{MLResample2dOptions/sizes}}[|index|] and return |desc|. | ||
| 1. Otherwise, set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |input|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] multiplied by |options|.{{MLResample2dOptions/scales}}[|index|]. |
There was a problem hiding this comment.
Should we use any one float to integer conversions (floor or ceil) for the result of input size multiplied by scale?
There was a problem hiding this comment.
Just confirming: Setting |desc|.{{MLOperandDescriptor/dimensions}} looks correct to me.
I did some grepping and I don't see other instances in the spec of "blah's shape" where blah isn't an MLOperand.
There was a problem hiding this comment.
Re: float-to-integer: Yes! The Chromium implementation uses floor() https://source.chromium.org/chromium/chromium/src/+/main:components/ml/webnn/graph_validation_utils.cc;l=986
There was a problem hiding this comment.
Also this is mentioned in #360 so I think after this lands we can close that issue?
There was a problem hiding this comment.
| 1. Otherwise, set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |input|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] multiplied by |options|.{{MLResample2dOptions/scales}}[|index|]. | |
| 1. Otherwise, set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to floor(|input|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] * |options|.{{MLResample2dOptions/scales}}[|index|]). |
There was a problem hiding this comment.
Yes, other resampling implementations also use floor too (which makes sense, because you wouldn't want 1.1 pixels to either yield empty space or repeat 1.1 pixels to 2 pixels of the same color).
There was a problem hiding this comment.
Yeah, * is more concise than "multiplied by".
inexorabletash
left a comment
There was a problem hiding this comment.
Please add floor() to the calculation, otherwise LGTM.
|
I've updated commit to address comments. Please take another look, thanks. |
index.bs
Outdated
| 1. For |index| in [=the range=] 0 to |options|.{{MLResample2dOptions/axes}}'s [=list/size=], exclusive: | ||
| 1. If |options|.{{MLResample2dOptions/sizes}} [=map/exists=], set |desc|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] to |options|.{{MLResample2dOptions/sizes}}[|index|] and return |desc|. | ||
| 1. Otherwise, set |desc|'s [=MLOperand/shape=][|options|.{{MLResample2dOptions/axes}}[|index|]] to |input|'s [=MLOperand/shape=][|index|] multiplied by |options|.{{MLResample2dOptions/scales}}. | ||
| 1. If |options|.{{MLResample2dOptions/sizes}} [=map/exists=], set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |options|.{{MLResample2dOptions/sizes}}[|index|] and return |desc|. |
There was a problem hiding this comment.
This step may not return |desc| in the loop. I understand the |desc| would be returned in the Line 4945.
| 1. If |options|.{{MLResample2dOptions/sizes}} [=map/exists=], set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |options|.{{MLResample2dOptions/sizes}}[|index|] and return |desc|. | |
| 1. If |options|.{{MLResample2dOptions/sizes}} [=map/exists=], set |desc|.{{MLOperandDescriptor/dimensions}}[|options|.{{MLResample2dOptions/axes}}[|index|]] to |options|.{{MLResample2dOptions/sizes}}[|index|] |
There was a problem hiding this comment.
Thanks @huningxin . Please review this update in new commit.
Preview | Diff