gromero commented on a change in pull request #10452:
URL: https://github.com/apache/tvm/pull/10452#discussion_r818650000
##########
File path: include/tvm/relay/attrs/image.h
##########
@@ -291,8 +292,25 @@ struct GridSampleAttrs : public
tvm::AttrsNode<GridSampleAttrs> {
TVM_ATTR_FIELD(padding_mode)
.set_default("zeros")
.describe(
- "Specify the padding mode to use."
- "zeros, border etc.");
+ "If :attr:'grid' has values outside the range of '[-1, 1]', the
corresponding"
+ "outputs are handled as defined by padding_mode. Options are"
+ "padding_mode='zeros': use '0' for out-of-bound grid locations,"
+ "padding_mode='border': use border values for out-of-bound grid
locations"
+ "padding_mode='reflection': use values at locations reflected by"
+ "the border for out-of-bound grid locations. For location far away"
+ "from the border, it will keep being reflected until becoming in
bound,"
+ "e.g., (normalized) pixel location 'x = -3.5' reflects by border
'-1'"
+ "and becomes 'x' = 1.5, then reflects by border '1' and becomes"
+ "'x' = -0.5");
+ TVM_ATTR_FIELD(align_corners)
+ .set_default(true)
+ .describe(
+ "Geometrically, we consider the pixels of the"
+ "input as squares rather than points."
Review comment:
There is a double space here, hence one should be removed.
##########
File path: python/tvm/relay/op/image/_image.py
##########
@@ -366,19 +366,41 @@ def compute_grid_sample(attrs, inputs, out_dtype):
method = attrs.method
layout = attrs.layout
padding_mode = attrs.padding_mode
- return [topi.image.grid_sample(inputs[0], inputs[1], method, layout,
padding_mode)]
+ align_corners = attrs.align_corners
+ return [
+ topi.image.grid_sample(
+ inputs[0],
+ inputs[1],
+ method,
+ layout,
+ padding_mode,
+ align_corners
+ )
+ ]
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])
+ if len(data) == 4:
+ 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])
+ elif len(data) == 5:
+ out = output_tensor((5,), "int64")
+ out[0] = int64(data[0])
+ out[1] = int64(data[1])
+ out[2] = int64(grid[2])
+ out[3] = int64(grid[3])
+ out[4] = int64(grid[4])
+ else:
+ msg = f"dimension is not surpported"
Review comment:
s/surpported/supported/ here
##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -2913,23 +2913,47 @@ def mv(self, inputs, _):
return _op.transform.squeeze(dense_result)
def grid_sampler(self, inputs, input_types):
- if inputs[2] == 0:
- mode = "bilinear"
- else:
- msg = "Only bilinear mode is supported in grid_sampler"
- raise NotImplementedError(msg)
-
- if inputs[3] == 0:
- padding_mode = "zeros"
- elif inputs[3] == 1:
- padding_mode = "border"
- else:
- msg = "Only zeros and border padding mode are supported in
grid_sampler"
- raise NotImplementedError(msg)
+ interpolate_mode = inputs[2]
+ padding_mode = inputs[3]
+ align_corners = inputs[4]
+ data_shape = self.infer_shape_with_prelude(inputs[0])
+
+ if len(data_shape) == 4:
+ layout = "NCHW"
+ axes = [0, 3, 1, 2]
+ grid = _op.transform.transpose(inputs[1], axes)
+ elif len(data_shape) == 5:
+ layout = "NCDHW"
+ axes = [0, 4, 1, 2, 3]
+ grid = _op.transform.transpose(inputs[1], axes)
+ else:
+ msg = f"only 4D and 5D are surpported."
+ raise ValueError(msg)
+
+ if interpolate_mode == 0:
+ interpolate_str = "bilinear"
+ elif interpolate_mode == 1:
+ interpolate_str = "nearest"
+ elif interpolate_mode == 2:
+ interpolate_str = "bicubic"
+ else:
+ msg = f"interpolation method {interpolate_mode} is not surpported"
Review comment:
s/surpported/supported/ here
##########
File path: include/tvm/relay/attrs/image.h
##########
@@ -291,8 +292,25 @@ struct GridSampleAttrs : public
tvm::AttrsNode<GridSampleAttrs> {
TVM_ATTR_FIELD(padding_mode)
.set_default("zeros")
.describe(
- "Specify the padding mode to use."
- "zeros, border etc.");
+ "If :attr:'grid' has values outside the range of '[-1, 1]', the
corresponding"
+ "outputs are handled as defined by padding_mode. Options are"
+ "padding_mode='zeros': use '0' for out-of-bound grid locations,"
+ "padding_mode='border': use border values for out-of-bound grid
locations"
+ "padding_mode='reflection': use values at locations reflected by"
+ "the border for out-of-bound grid locations. For location far away"
+ "from the border, it will keep being reflected until becoming in
bound,"
+ "e.g., (normalized) pixel location 'x = -3.5' reflects by border
'-1'"
+ "and becomes 'x' = 1.5, then reflects by border '1' and becomes"
+ "'x' = -0.5");
+ TVM_ATTR_FIELD(align_corners)
+ .set_default(true)
+ .describe(
+ "Geometrically, we consider the pixels of the"
+ "input as squares rather than points."
Review comment:
Shouldn't also the options `nearest` and `bicubic` be
added/listed/explained for the `method` attribute field? Similarly to what you
did for `padding_mode` and `align_corners` options?
##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -2913,23 +2913,47 @@ def mv(self, inputs, _):
return _op.transform.squeeze(dense_result)
def grid_sampler(self, inputs, input_types):
- if inputs[2] == 0:
- mode = "bilinear"
- else:
- msg = "Only bilinear mode is supported in grid_sampler"
- raise NotImplementedError(msg)
-
- if inputs[3] == 0:
- padding_mode = "zeros"
- elif inputs[3] == 1:
- padding_mode = "border"
- else:
- msg = "Only zeros and border padding mode are supported in
grid_sampler"
- raise NotImplementedError(msg)
+ interpolate_mode = inputs[2]
+ padding_mode = inputs[3]
+ align_corners = inputs[4]
+ data_shape = self.infer_shape_with_prelude(inputs[0])
+
+ if len(data_shape) == 4:
+ layout = "NCHW"
+ axes = [0, 3, 1, 2]
+ grid = _op.transform.transpose(inputs[1], axes)
+ elif len(data_shape) == 5:
+ layout = "NCDHW"
+ axes = [0, 4, 1, 2, 3]
+ grid = _op.transform.transpose(inputs[1], axes)
+ else:
+ msg = f"only 4D and 5D are surpported."
+ raise ValueError(msg)
+
+ if interpolate_mode == 0:
+ interpolate_str = "bilinear"
+ elif interpolate_mode == 1:
+ interpolate_str = "nearest"
+ elif interpolate_mode == 2:
+ interpolate_str = "bicubic"
+ else:
+ msg = f"interpolation method {interpolate_mode} is not surpported"
+ raise ValueError(msg)
+
+ if padding_mode == 0:
+ padding_mode_str = "zeros"
+ elif padding_mode == 1:
+ padding_mode_str = "border"
+ elif padding_mode == 2:
+ padding_mode_str = 'reflection'
+ else:
+ msg = f"padding_mode {padding_mode} is not surpportted"
Review comment:
s/surpported/supported/ here
##########
File path: python/tvm/relay/frontend/pytorch.py
##########
@@ -2913,23 +2913,47 @@ def mv(self, inputs, _):
return _op.transform.squeeze(dense_result)
def grid_sampler(self, inputs, input_types):
- if inputs[2] == 0:
- mode = "bilinear"
- else:
- msg = "Only bilinear mode is supported in grid_sampler"
- raise NotImplementedError(msg)
-
- if inputs[3] == 0:
- padding_mode = "zeros"
- elif inputs[3] == 1:
- padding_mode = "border"
- else:
- msg = "Only zeros and border padding mode are supported in
grid_sampler"
- raise NotImplementedError(msg)
+ interpolate_mode = inputs[2]
+ padding_mode = inputs[3]
+ align_corners = inputs[4]
+ data_shape = self.infer_shape_with_prelude(inputs[0])
+
+ if len(data_shape) == 4:
+ layout = "NCHW"
+ axes = [0, 3, 1, 2]
+ grid = _op.transform.transpose(inputs[1], axes)
+ elif len(data_shape) == 5:
+ layout = "NCDHW"
+ axes = [0, 4, 1, 2, 3]
+ grid = _op.transform.transpose(inputs[1], axes)
+ else:
+ msg = f"only 4D and 5D are surpported."
Review comment:
s/surpported/supported/ here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]