You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2019/12/20 01:17:46 UTC
[GitHub] [incubator-tvm] yongwww opened a new pull request #4551: [Relay]
add max_pool3d in relay and TF converter
yongwww opened a new pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551
@optima2005 @masahi @zhiics @kevinthesun
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] optima2005 commented on a change in pull request
#4551: [Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
optima2005 commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360631021
##########
File path: python/tvm/relay/frontend/tensorflow.py
##########
@@ -122,6 +122,71 @@ def _impl(inputs, attr, params):
return get_relay_op(name)(*inputs)
return _impl
+def _pool3d(name):
+ def _impl(inputs, attr, params):
+ attr['data_format'] = attr['data_format'].decode("utf-8")
+ flip_layout = False
+
+ input_shape = attr['_input_shapes'][inputs[0]]
+
+ if attr['data_format'] == 'NDHWC':
+ attr['kernel_shape'] = (attr['ksize'][1], attr['ksize'][2], attr['ksize'][3])
+ attr['strides'] = (attr['strides'][1], attr['strides'][2], attr['strides'][3])
+ elif attr['data_format'] == 'NCDHW':
+ attr['kernel_shape'] = (attr['ksize'][2], attr['ksize'][3], attr['ksize'][4])
+ attr['strides'] = (attr['strides'][2], attr['strides'][3], attr['strides'][4])
+ else:
+ msg = 'Value {} of attribute "data_format" of operator Pooling ' \
+ 'is not valid.'
+ raise tvm.error.OpAttributeInvalid(msg.format(attr['data_format']))
+ if attr['data_format'] == "NDHWC":
+ tmp_shape = attr['_input_shapes'][inputs[0]]
+ input_shape = [tmp_shape[ii] for ii in (0, 4, 1, 2, 3)]
+ inputs[0] = _op.transpose(inputs[0], axes=(0, 4, 1, 2, 3))
+ attr['data_format'] = "NCDHW"
+ flip_layout = True
+
+ attr['padding'] = attr['padding'].decode("utf-8")
+
+ if attr['padding'] == 'VALID':
+ attr['padding'] = [0, 0, 0, 0, 0, 0]
+ elif attr['padding'] == 'SAME':
+ stride_d, stride_h, stride_w = attr['strides']
+ kernel_d, kernel_h, kernel_w = attr['kernel_shape']
+ if attr['data_format'] == 'NDHWC':
+ in_d = input_shape[1]
+ in_h = input_shape[2]
+ in_w = input_shape[3]
+ else:
+ in_d = input_shape[2]
+ in_h = input_shape[3]
+ in_w = input_shape[4]
+ pad_d = _get_pad_pair(in_d, kernel_d, stride_d)
+ pad_v = _get_pad_pair(in_h, kernel_h, stride_h)
+ pad_h = _get_pad_pair(in_w, kernel_w, stride_w)
+
+ attr['padding'] = [pad_d[0], pad_v[0], pad_h[0], pad_d[1], pad_v[1], pad_h[1]]
+ else:
+ msg = 'Value {} in attribute "padding" of operator Pooling is ' \
+ 'not valid.'
+ raise tvm.error.OpAttributeInvalid(msg.format(attr['padding']))
+
+ if name == "avg_pool":
+ attr['count_include_pad'] = False
+ attr['ceil_mode'] = False
Review comment:
Why need hardcode ceil_mode?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] yongwww commented on issue #4551: [Relay] add
max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
yongwww commented on issue #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#issuecomment-568206187
@optima2005 @masahi fixed comments, pls take another look
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] optima2005 commented on a change in pull request
#4551: [Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
optima2005 commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360630661
##########
File path: tests/python/frontend/tensorflow/test_forward.py
##########
@@ -237,16 +237,43 @@ def _test_pooling_iteration(input_shape, **kwargs):
def _test_pooling(input_shape, **kwargs):
_test_pooling_iteration(input_shape, **kwargs)
- if is_gpu_available() and (len(input_shape) == 4):
- input_shape = [input_shape[ii] for ii in (0, 3, 1, 2)]
- kwargs['data_format'] = 'NCHW'
- _test_pooling_iteration(input_shape, **kwargs)
+ if is_gpu_available():
+ if len(input_shape) == 4:
+ input_shape = [input_shape[ii] for ii in (0, 3, 1, 2)]
+ kwargs['data_format'] = 'NCHW'
+ _test_pooling_iteration(input_shape, **kwargs)
+ elif len(input_shape) == 5:
+ input_shape = [input_shape[ii] for ii in (0, 4, 1, 2, 3)]
+ kwargs['data_format'] = 'NCDHW'
+ _test_pooling_iteration(input_shape, **kwargs)
def test_forward_pooling():
""" Pooling """
+ # TensorFlow only supports NDHWC for max_pool3d on CPU
+ for pool_type in ['MAX', 'AVG']:
+
+ _test_pooling(input_shape=[1, 3, 32, 32, 32],
+ window_shape=[2, 2, 2],
+ padding='VALID',
+ pooling_type=pool_type,
+ dilation_rate=[1, 1, 1],
+ strides=[2, 2, 2])
+
+ _test_pooling(input_shape=[1, 3, 32, 32, 32],
+ window_shape=[1, 1, 1],
+ padding='SAME',
+ pooling_type=pool_type,
+ dilation_rate=[1, 1, 1],
+ strides=[1, 1, 1])
+
+ _test_pooling(input_shape=[1, 3, 32, 32, 32],
+ window_shape=[2, 2, 2],
+ padding='SAME',
+ pooling_type=pool_type,
+ dilation_rate=[1, 1, 1],
+ strides=[2, 2, 2])
Review comment:
Need add "NDHWC" layout cases.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] optima2005 commented on a change in pull request
#4551: [Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
optima2005 commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360631021
##########
File path: python/tvm/relay/frontend/tensorflow.py
##########
@@ -122,6 +122,71 @@ def _impl(inputs, attr, params):
return get_relay_op(name)(*inputs)
return _impl
+def _pool3d(name):
+ def _impl(inputs, attr, params):
+ attr['data_format'] = attr['data_format'].decode("utf-8")
+ flip_layout = False
+
+ input_shape = attr['_input_shapes'][inputs[0]]
+
+ if attr['data_format'] == 'NDHWC':
+ attr['kernel_shape'] = (attr['ksize'][1], attr['ksize'][2], attr['ksize'][3])
+ attr['strides'] = (attr['strides'][1], attr['strides'][2], attr['strides'][3])
+ elif attr['data_format'] == 'NCDHW':
+ attr['kernel_shape'] = (attr['ksize'][2], attr['ksize'][3], attr['ksize'][4])
+ attr['strides'] = (attr['strides'][2], attr['strides'][3], attr['strides'][4])
+ else:
+ msg = 'Value {} of attribute "data_format" of operator Pooling ' \
+ 'is not valid.'
+ raise tvm.error.OpAttributeInvalid(msg.format(attr['data_format']))
+ if attr['data_format'] == "NDHWC":
+ tmp_shape = attr['_input_shapes'][inputs[0]]
+ input_shape = [tmp_shape[ii] for ii in (0, 4, 1, 2, 3)]
+ inputs[0] = _op.transpose(inputs[0], axes=(0, 4, 1, 2, 3))
+ attr['data_format'] = "NCDHW"
+ flip_layout = True
+
+ attr['padding'] = attr['padding'].decode("utf-8")
+
+ if attr['padding'] == 'VALID':
+ attr['padding'] = [0, 0, 0, 0, 0, 0]
+ elif attr['padding'] == 'SAME':
+ stride_d, stride_h, stride_w = attr['strides']
+ kernel_d, kernel_h, kernel_w = attr['kernel_shape']
+ if attr['data_format'] == 'NDHWC':
+ in_d = input_shape[1]
+ in_h = input_shape[2]
+ in_w = input_shape[3]
+ else:
+ in_d = input_shape[2]
+ in_h = input_shape[3]
+ in_w = input_shape[4]
+ pad_d = _get_pad_pair(in_d, kernel_d, stride_d)
+ pad_v = _get_pad_pair(in_h, kernel_h, stride_h)
+ pad_h = _get_pad_pair(in_w, kernel_w, stride_w)
+
+ attr['padding'] = [pad_d[0], pad_v[0], pad_h[0], pad_d[1], pad_v[1], pad_h[1]]
+ else:
+ msg = 'Value {} in attribute "padding" of operator Pooling is ' \
+ 'not valid.'
+ raise tvm.error.OpAttributeInvalid(msg.format(attr['padding']))
+
+ if name == "avg_pool":
+ attr['count_include_pad'] = False
+ attr['ceil_mode'] = False
Review comment:
Why need hardcode ceil_mode?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] masahi commented on a change in pull request #4551:
[Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360670805
##########
File path: tests/python/relay/test_op_level2.py
##########
@@ -532,6 +532,72 @@ def test_pool2d():
_test_global_pool2d(relay.nn.global_avg_pool2d, np.mean)
+def test_pool3d():
+
+ def _test_pool3d_baseline(np_data, in_shape, kernal, strides, padding,
Review comment:
move this function to topi/python/topi/testing and rename it to pool3d_python
Also use that function to replace the hard coded one in the topi test https://github.com/apache/incubator-tvm/blob/master/topi/tests/python/test_topi_pooling.py#L298-L316
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] optima2005 commented on a change in pull request
#4551: [Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
optima2005 commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360631001
##########
File path: python/tvm/relay/frontend/tensorflow.py
##########
@@ -122,6 +122,71 @@ def _impl(inputs, attr, params):
return get_relay_op(name)(*inputs)
return _impl
+def _pool3d(name):
+ def _impl(inputs, attr, params):
+ attr['data_format'] = attr['data_format'].decode("utf-8")
+ flip_layout = False
+
+ input_shape = attr['_input_shapes'][inputs[0]]
+
+ if attr['data_format'] == 'NDHWC':
+ attr['kernel_shape'] = (attr['ksize'][1], attr['ksize'][2], attr['ksize'][3])
+ attr['strides'] = (attr['strides'][1], attr['strides'][2], attr['strides'][3])
+ elif attr['data_format'] == 'NCDHW':
+ attr['kernel_shape'] = (attr['ksize'][2], attr['ksize'][3], attr['ksize'][4])
+ attr['strides'] = (attr['strides'][2], attr['strides'][3], attr['strides'][4])
+ else:
+ msg = 'Value {} of attribute "data_format" of operator Pooling ' \
+ 'is not valid.'
+ raise tvm.error.OpAttributeInvalid(msg.format(attr['data_format']))
+ if attr['data_format'] == "NDHWC":
+ tmp_shape = attr['_input_shapes'][inputs[0]]
+ input_shape = [tmp_shape[ii] for ii in (0, 4, 1, 2, 3)]
+ inputs[0] = _op.transpose(inputs[0], axes=(0, 4, 1, 2, 3))
+ attr['data_format'] = "NCDHW"
+ flip_layout = True
+
+ attr['padding'] = attr['padding'].decode("utf-8")
+
+ if attr['padding'] == 'VALID':
+ attr['padding'] = [0, 0, 0, 0, 0, 0]
+ elif attr['padding'] == 'SAME':
+ stride_d, stride_h, stride_w = attr['strides']
+ kernel_d, kernel_h, kernel_w = attr['kernel_shape']
+ if attr['data_format'] == 'NDHWC':
+ in_d = input_shape[1]
+ in_h = input_shape[2]
+ in_w = input_shape[3]
+ else:
+ in_d = input_shape[2]
+ in_h = input_shape[3]
+ in_w = input_shape[4]
+ pad_d = _get_pad_pair(in_d, kernel_d, stride_d)
+ pad_v = _get_pad_pair(in_h, kernel_h, stride_h)
+ pad_h = _get_pad_pair(in_w, kernel_w, stride_w)
+
+ attr['padding'] = [pad_d[0], pad_v[0], pad_h[0], pad_d[1], pad_v[1], pad_h[1]]
+ else:
+ msg = 'Value {} in attribute "padding" of operator Pooling is ' \
+ 'not valid.'
+ raise tvm.error.OpAttributeInvalid(msg.format(attr['padding']))
+
+ if name == "avg_pool":
+ attr['count_include_pad'] = False
+ attr['ceil_mode'] = False
+ attr['data_format'] = 'NCDHW'
Review comment:
This line is not necessory.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] optima2005 commented on a change in pull request
#4551: [Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
optima2005 commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360630075
##########
File path: tests/python/relay/test_op_level2.py
##########
@@ -532,6 +532,72 @@ def test_pool2d():
_test_global_pool2d(relay.nn.global_avg_pool2d, np.mean)
+def test_pool3d():
+
+ def _test_pool3d_baseline(np_data, in_shape, kernal, strides, padding,
+ out_shape, pool_type, count_include_pad=True):
+ # default layout is "NCDHW"
+ dtype = "float32"
+ n, ic, id, ih, iw = in_shape
+ kd, kw, kh = kernal
+ sd, sw, sh = strides
Review comment:
kd, dh, kw
sd, sh, sw
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] optima2005 commented on a change in pull request
#4551: [Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
optima2005 commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360630926
##########
File path: python/tvm/relay/frontend/tensorflow.py
##########
@@ -122,6 +122,71 @@ def _impl(inputs, attr, params):
return get_relay_op(name)(*inputs)
return _impl
+def _pool3d(name):
+ def _impl(inputs, attr, params):
+ attr['data_format'] = attr['data_format'].decode("utf-8")
+ flip_layout = False
+
+ input_shape = attr['_input_shapes'][inputs[0]]
+
+ if attr['data_format'] == 'NDHWC':
+ attr['kernel_shape'] = (attr['ksize'][1], attr['ksize'][2], attr['ksize'][3])
+ attr['strides'] = (attr['strides'][1], attr['strides'][2], attr['strides'][3])
+ elif attr['data_format'] == 'NCDHW':
+ attr['kernel_shape'] = (attr['ksize'][2], attr['ksize'][3], attr['ksize'][4])
+ attr['strides'] = (attr['strides'][2], attr['strides'][3], attr['strides'][4])
+ else:
+ msg = 'Value {} of attribute "data_format" of operator Pooling ' \
+ 'is not valid.'
+ raise tvm.error.OpAttributeInvalid(msg.format(attr['data_format']))
+ if attr['data_format'] == "NDHWC":
+ tmp_shape = attr['_input_shapes'][inputs[0]]
+ input_shape = [tmp_shape[ii] for ii in (0, 4, 1, 2, 3)]
+ inputs[0] = _op.transpose(inputs[0], axes=(0, 4, 1, 2, 3))
+ attr['data_format'] = "NCDHW"
Review comment:
may need to add
```
attr['_input_shapes'][inputs[0]] = input_shape
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] optima2005 commented on a change in pull request
#4551: [Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
optima2005 commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360630617
##########
File path: tests/python/frontend/tensorflow/test_forward.py
##########
@@ -237,16 +237,43 @@ def _test_pooling_iteration(input_shape, **kwargs):
def _test_pooling(input_shape, **kwargs):
_test_pooling_iteration(input_shape, **kwargs)
- if is_gpu_available() and (len(input_shape) == 4):
- input_shape = [input_shape[ii] for ii in (0, 3, 1, 2)]
- kwargs['data_format'] = 'NCHW'
- _test_pooling_iteration(input_shape, **kwargs)
+ if is_gpu_available():
+ if len(input_shape) == 4:
+ input_shape = [input_shape[ii] for ii in (0, 3, 1, 2)]
+ kwargs['data_format'] = 'NCHW'
+ _test_pooling_iteration(input_shape, **kwargs)
+ elif len(input_shape) == 5:
+ input_shape = [input_shape[ii] for ii in (0, 4, 1, 2, 3)]
+ kwargs['data_format'] = 'NCDHW'
Review comment:
kwargs['data_format'] should be input parameter to cover "NDHWC" layout.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] masahi commented on issue #4551: [Relay] add
max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
masahi commented on issue #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#issuecomment-567858648
@optima2005 can you take a look? sorry we missed adding relay tests in the previous PR.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] yongwww commented on a change in pull request
#4551: [Relay] add max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
yongwww commented on a change in pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551#discussion_r360722847
##########
File path: tests/python/relay/test_op_level2.py
##########
@@ -532,6 +532,72 @@ def test_pool2d():
_test_global_pool2d(relay.nn.global_avg_pool2d, np.mean)
+def test_pool3d():
+
+ def _test_pool3d_baseline(np_data, in_shape, kernal, strides, padding,
Review comment:
comments were incorporated, pls take another look
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
[GitHub] [incubator-tvm] masahi merged pull request #4551: [Relay] add
max_pool3d in relay and TF converter
Posted by GitBox <gi...@apache.org>.
masahi merged pull request #4551: [Relay] add max_pool3d in relay and TF converter
URL: https://github.com/apache/incubator-tvm/pull/4551
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services