forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Relay][Op] Adaptive pooling (apache#3085)
* Add topi adaptive_pool * Use adaptive_pool to compute global_pool * Add relay adaptive pool2d * Fix lint * Fix typo * Minor change * Change support level to 10 * Add contrib * Remove global pool schedule * Add contrib module * Fix lint * Update doc * Update doc
- Loading branch information
1 parent
82dfab1
commit c1648d0
Showing
29 changed files
with
709 additions
and
83 deletions.
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# pylint: disable=wildcard-import, unused-import, unused-wildcard-import | ||
"""Contrib operators.""" | ||
# Re-export in a specific file name so that autodoc can pick it up | ||
from .op.contrib import * |
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
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# pylint: disable=wildcard-import | ||
"""Neural network related operators.""" | ||
from __future__ import absolute_import as _abs | ||
from .contrib import * | ||
from . import _contrib |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# pylint: disable=invalid-name, unused-argument | ||
"""Backend compiler related feature registration""" | ||
from __future__ import absolute_import | ||
|
||
import topi | ||
from .. import op as reg | ||
from ..op import OpPattern | ||
|
||
|
||
# adaptive_max_pool2d | ||
@reg.register_schedule("contrib.adaptive_max_pool2d") | ||
def schedule_adaptive_max_pool2d(_, outs, target): | ||
"""Schedule definition of adaptive_max_pool2d""" | ||
with target: | ||
return topi.generic.schedule_adaptive_pool(outs) | ||
|
||
reg.register_pattern("contrib.adaptive_max_pool2d", OpPattern.OUT_ELEMWISE_FUSABLE) | ||
|
||
|
||
# adaptive_avg_pool2d | ||
@reg.register_schedule("contrib.adaptive_avg_pool2d") | ||
def schedule_adaptive_avg_pool2d(_, outs, target): | ||
"""Schedule definition of adaptive_avg_pool2d""" | ||
with target: | ||
return topi.generic.schedule_adaptive_pool(outs) | ||
|
||
reg.register_pattern("contrib.adaptive_avg_pool2d", OpPattern.OUT_ELEMWISE_FUSABLE) |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
"""Constructor APIs""" | ||
from ...._ffi.function import _init_api | ||
|
||
_init_api("relay.op.contrib._make", __name__) |
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
#pylint: disable=invalid-name, too-many-lines | ||
"""Contrib operations.""" | ||
from __future__ import absolute_import as _abs | ||
from . import _make | ||
|
||
|
||
def adaptive_max_pool2d(data, | ||
output_size=None, | ||
layout="NCHW"): | ||
r"""2D adaptive max pooling operator. This operator is experimental. | ||
This operator takes data as input and does 2D max value calculation | ||
across each window represented by WxH. | ||
In the default case, where the data_layout is `NCHW` | ||
a data Tensor with shape `(batch_size, in_channels, height, width)`, | ||
to produce an output Tensor with shape | ||
(batch_size, in_channels, output_height, output_width). | ||
The pooling kernel and stride sizes are automatically chosen for | ||
desired output sizes. | ||
For output_size: | ||
If this argument is not provided, input height and width will be used | ||
as output height and width. | ||
If a single integer is provided for output_size, the output size is | ||
(N x C x output_size x output_size) for any input (NCHW). | ||
If a tuple of integers (height, width) are provided for output_size, | ||
the output size is (N x C x height x width) for any input (NCHW). | ||
Parameters | ||
---------- | ||
data : tvm.relay.Expr | ||
The input data to the operator. | ||
output_size : tuple of int. optional | ||
Output height and width. | ||
layout : str, optional | ||
Layout of the input. | ||
Returns | ||
------- | ||
result : tvm.relay.Expr | ||
The computed result. | ||
""" | ||
output_size = [] or output_size | ||
return _make.adaptive_max_pool2d(data, output_size, layout) | ||
|
||
def adaptive_avg_pool2d(data, | ||
output_size=None, | ||
layout="NCHW"): | ||
r"""2D adaptive average pooling operator. This operator is experimental. | ||
This operator takes data as input and does 2D average value calculation | ||
across each window represented by WxH. | ||
In the default case, where the data_layout is `NCHW` | ||
a data Tensor with shape `(batch_size, in_channels, height, width)`, | ||
to produce an output Tensor with shape | ||
(batch_size, in_channels, output_height, output_width). | ||
The pooling kernel and stride sizes are automatically chosen for | ||
desired output sizes. | ||
For output_size: | ||
If this argument is not provided, input height and width will be used | ||
as output height and width. | ||
If a single integer is provided for output_size, the output size is | ||
(N x C x output_size x output_size) for any input (NCHW). | ||
If a tuple of integers (height, width) are provided for output_size, | ||
the output size is (N x C x height x width) for any input (NCHW). | ||
Parameters | ||
---------- | ||
data : tvm.relay.Expr | ||
The input data to the operator. | ||
output_size : tuple of int. optional | ||
Output height and width. | ||
layout : str, optional | ||
Layout of the input. | ||
Returns | ||
------- | ||
result : tvm.relay.Expr | ||
The computed result. | ||
""" | ||
output_size = [] or output_size | ||
return _make.adaptive_avg_pool2d(data, output_size, layout) |
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
Oops, something went wrong.