Skip to content

Comments

Bugfix: Updated the step of calculating output sizes by scales for resample2d#611

Merged
fdwr merged 3 commits intowebmachinelearning:mainfrom
BruceDai:fix_resample2d_outputsizes
Mar 21, 2024
Merged

Bugfix: Updated the step of calculating output sizes by scales for resample2d#611
fdwr merged 3 commits intowebmachinelearning:mainfrom
BruceDai:fix_resample2d_outputsizes

Conversation

@BruceDai
Copy link
Contributor

@BruceDai BruceDai commented Mar 20, 2024

@BruceDai BruceDai changed the title Fixed the step of calculating output sizes by scales for resample2d [Bugfix] Updated the step of calculating output sizes by scales for resample2d Mar 20, 2024
@BruceDai BruceDai changed the title [Bugfix] Updated the step of calculating output sizes by scales for resample2d Bugfix: Updated the step of calculating output sizes by scales for resample2d Mar 20, 2024
@BruceDai
Copy link
Contributor Author

@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|].
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use any one float to integer conversions (floor or ceil) for the result of input size multiplied by scale?

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this is mentioned in #360 so I think after this lands we can close that issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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|]).

Copy link
Collaborator

@fdwr fdwr Mar 21, 2024

Choose a reason for hiding this comment

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

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).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, * is more concise than "multiplied by".

Copy link
Contributor

@inexorabletash inexorabletash left a comment

Choose a reason for hiding this comment

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

Please add floor() to the calculation, otherwise LGTM.

@BruceDai
Copy link
Contributor Author

I've updated commit to address comments. Please take another look, thanks.

Copy link
Contributor

@inexorabletash inexorabletash left a comment

Choose a reason for hiding this comment

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

LGTM!

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|.
Copy link
Contributor

Choose a reason for hiding this comment

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

This step may not return |desc| in the loop. I understand the |desc| would be returned in the Line 4945.

Suggested change
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|]

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 @huningxin . Please review this update in new commit.

Copy link
Contributor

@huningxin huningxin left a comment

Choose a reason for hiding this comment

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

LGTM

@fdwr fdwr merged commit 24edf7f into webmachinelearning:main Mar 21, 2024
github-actions bot added a commit that referenced this pull request Mar 21, 2024
…sample2d (#611)

SHA: 24edf7f
Reason: push, by fdwr

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants