-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Register shape functions for some image related ops #6373
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
57bd2b8
debugging
Laurawly 7b8d5d9
added three shape funcs
Laurawly 71f9fea
fix lint
Laurawly 0331bb1
address comment
Laurawly c24c09a
resolve conflicts
Laurawly adb32ad
resolve conflicts
Laurawly cf0cc3f
resolve conflicts
Laurawly 93ed8e0
resolve conflicts
Laurawly 771cd57
resolve conflicts
Laurawly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,45 @@ def compute_resize(attrs, inputs, out_type): | |
reg.register_injective_schedule("image.resize") | ||
|
||
|
||
@script | ||
def _resize_shape_func(image_shape, size, batch_axis, height_axis, width_axis, channel_axis): | ||
out = output_tensor((4,), "int64") | ||
out[batch_axis] = int64(image_shape[0]) | ||
out[height_axis] = int64(size[0]) | ||
out[width_axis] = int64(size[1]) | ||
out[channel_axis] = image_shape[channel_axis] | ||
return out | ||
|
||
|
||
@reg.register_shape_func("image.resize", False) | ||
def resize_shape_func(attrs, inputs, _): | ||
""" | ||
Shape function for resize op. | ||
""" | ||
layout = attrs.layout | ||
height_axis = width_axis = channel_axis = 1 | ||
for i, letter in enumerate(layout): | ||
if letter == "N": | ||
batch_axis = i | ||
if letter == "H": | ||
height_axis = i | ||
if letter == "W": | ||
width_axis = i | ||
if letter == "C": | ||
channel_axis = i | ||
size = get_const_tuple(attrs.size) | ||
return [ | ||
_resize_shape_func( | ||
inputs[0], | ||
convert(size), | ||
convert(batch_axis), | ||
convert(height_axis), | ||
convert(width_axis), | ||
convert(channel_axis), | ||
) | ||
] | ||
|
||
|
||
@reg.register_compute("image.resize3d") | ||
def compute_resize3d(attrs, inputs, out_type): | ||
size = attrs.size | ||
|
@@ -134,6 +173,25 @@ def compute_affine_grid(attrs, inputs, out_dtype): | |
reg.register_injective_schedule("image.affine_grid") | ||
|
||
|
||
@script | ||
def _affine_grid_func(data, target_shape): | ||
out = output_tensor((4,), "int64") | ||
out[0] = int64(data[0]) | ||
out[1] = int64(2) | ||
out[2] = int64(target_shape[0]) | ||
out[3] = int64(target_shape[1]) | ||
return out | ||
|
||
|
||
@reg.register_shape_func("image.affine_grid", False) | ||
def affine_grid_func(attrs, inputs, _): | ||
""" | ||
Shape function for affine_grid op. | ||
""" | ||
target_shape = get_const_tuple(attrs.target_shape) | ||
return [_affine_grid_func(inputs[0], convert(target_shape))] | ||
|
||
|
||
# grid_sample | ||
@reg.register_compute("image.grid_sample") | ||
def compute_grid_sample(attrs, inputs, out_dtype): | ||
|
@@ -143,3 +201,21 @@ def compute_grid_sample(attrs, inputs, out_dtype): | |
|
||
|
||
reg.register_injective_schedule("image.grid_sample") | ||
|
||
|
||
@script | ||
def _grid_sample_func(data, grid): | ||
out = output_tensor((4,), "int64") | ||
out[0] = int64(data[0]) | ||
out[1] = int64(data[1]) | ||
out[2] = int64(grid[2]) | ||
out[3] = int64(grid[3]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question here. different layout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I think it only supports NCHW |
||
return out | ||
|
||
|
||
@reg.register_shape_func("image.grid_sample", False) | ||
def grid_sample_func(attrs, inputs, _): | ||
""" | ||
Shape function for grid_sample op. | ||
""" | ||
return [_grid_sample_func(inputs[0], inputs[1])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we support different layout for
affine_grid
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I don't think so.