forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Relay] Conv2D padding representation (apache#4787)
* enforce 4-way padding * add util with get_pad_tuple * delete unnecessary arguments * fix lint * add container.Array case * fix cudnn conv2d asymmetric padding logic * rename get_pad_tuple to get_pad_tuple2d * revert change for topi/python/topi/nn/conv2d.py * add get_pad_tuple2d for several contrib conv2d ops * add get_pad_tuple2d for all conv2d ops
- Loading branch information
Showing
5 changed files
with
90 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# 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-variable | ||
"""NN operator common utilities""" | ||
from __future__ import absolute_import | ||
from .... import container | ||
|
||
def get_pad_tuple2d(padding): | ||
"""Common code to get the pad option | ||
Parameters | ||
---------- | ||
padding : Union[int, Tuple[int, ...]] | ||
Padding size | ||
Returns | ||
------- | ||
pad_top : int | ||
Padding size on top | ||
pad_left : int | ||
Padding size on left | ||
pad_down : int | ||
Padding size on down. | ||
pad_right : int | ||
Padding size on right. | ||
""" | ||
# compute the padding size | ||
if isinstance(padding, container.Array): | ||
padding = list(padding) | ||
if isinstance(padding, (tuple, list)): | ||
if len(padding) == 2: | ||
pad_h = padding[0] * 2 | ||
pad_w = padding[1] * 2 | ||
elif len(padding) == 4: | ||
return padding[0], padding[1], padding[2], padding[3] | ||
else: | ||
raise ValueError("Size of padding can only be 2 or 4") | ||
elif isinstance(padding, int): | ||
pad_h = pad_w = padding * 2 | ||
else: | ||
raise ValueError("Unknown padding option %s" % padding) | ||
pad_top = (pad_h + 1) // 2 | ||
pad_left = (pad_w + 1) // 2 | ||
return pad_top, pad_left, pad_h - pad_top, pad_w - pad_left |
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