forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RELAY][OP] Operators. pool2d, global_pool2d, batch_flatten, tanh, si…
…gmoid, floor, ceil, trunc, abs, negative, multiply, mod, pow, resize (apache#1813)
- Loading branch information
1 parent
5078e8e
commit 4fd3604
Showing
28 changed files
with
1,648 additions
and
71 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,41 @@ | ||
/*! | ||
* Copyright (c) 2018 by Contributors | ||
* \file tvm/relay/attrs/image.h | ||
* \brief Auxiliary attributes for image operators. | ||
*/ | ||
#ifndef TVM_RELAY_ATTRS_IMAGE_H_ | ||
#define TVM_RELAY_ATTRS_IMAGE_H_ | ||
|
||
#include <tvm/attrs.h> | ||
#include <string> | ||
|
||
namespace tvm { | ||
namespace relay { | ||
|
||
/*! \brief Attributes used in image resize operator */ | ||
struct ResizeAttrs : public tvm::AttrsNode<ResizeAttrs> { | ||
Array<IndexExpr> size; | ||
std::string layout; | ||
std::string method; | ||
bool align_corners; | ||
|
||
TVM_DECLARE_ATTRS(ResizeAttrs, "relay.attrs.ResizeAttrs") { | ||
TVM_ATTR_FIELD(size).set_default(NullValue<Array<IndexExpr> >()) | ||
.describe("Output Size."); | ||
TVM_ATTR_FIELD(layout).set_default("NCHW") | ||
.describe("Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc." | ||
"'N', 'C', 'H', 'W' stands for batch, channel, height, and width" | ||
"dimensions respectively. Resize is applied on the 'H' and" | ||
"'W' dimensions."); | ||
TVM_ATTR_FIELD(method).set_default("BILINEAR") | ||
.describe("Specify the mode to use for scaling." | ||
"NEAREST_NEIGHBOR - Nearest Neighbor" | ||
"BILINEAR - Bilinear Interpolation"); | ||
TVM_ATTR_FIELD(align_corners).set_default(false) | ||
.describe("Should be true to preserve the values at the corner pixels"); | ||
} | ||
}; | ||
|
||
} // namespace relay | ||
} // namespace tvm | ||
#endif // TVM_RELAY_ATTRS_IMAGE_H_ |
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,17 @@ | ||
/*! | ||
* Copyright (c) 2018 by Contributors | ||
* \file tvm/relay/attrs/vision.h | ||
* \brief Auxiliary attributes for vision operators. | ||
*/ | ||
#ifndef TVM_RELAY_ATTRS_VISION_H_ | ||
#define TVM_RELAY_ATTRS_VISION_H_ | ||
|
||
#include <tvm/attrs.h> | ||
#include <string> | ||
|
||
namespace tvm { | ||
namespace relay { | ||
|
||
} // namespace relay | ||
} // namespace tvm | ||
#endif // TVM_RELAY_ATTRS_VISION_H_ |
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,4 @@ | ||
# pylint: disable=wildcard-import, unused-import, unused-wildcard-import | ||
"""Image nets related operators.""" | ||
# Re-export in a specific file name so that autodoc can pick it up | ||
from .op.image 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# pylint: disable=wildcard-import | ||
"""Image network related operators.""" | ||
from __future__ import absolute_import as _abs | ||
from .image 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"""Constructor APIs""" | ||
from ...._ffi.function import _init_api | ||
|
||
_init_api("relay.op.image._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,42 @@ | ||
"""Image operations.""" | ||
from __future__ import absolute_import as _abs | ||
from . import _make | ||
|
||
def resize(data, | ||
size, | ||
layout="NCHW", | ||
method="BILINEAR", | ||
align_corners=False): | ||
"""Image resize operator. | ||
This operator takes data as input and does 2D scaling to the given scale factor. | ||
In the default case, where the data_layout is `NCHW` | ||
with data of shape (n, c, h, w) | ||
out will have a shape (n, c, size[0], size[1]) | ||
method indicates the algorithm to be used while calculating ghe out value | ||
and method can be one of ("BILINEAR", "NEAREST_NEIGHBOR") | ||
Parameters | ||
---------- | ||
data : relay.Expr | ||
The input data to the operator. | ||
size: Tuple of Expr | ||
The out size to which the image will be resized. | ||
layout : str, optional | ||
Layout of the input. | ||
method : str, optional | ||
Scale method to used [NEAREST_NEIGHBOR, BILINEAR]. | ||
align_corners : int, optional | ||
Should be true to preserve the values at the corner pixels | ||
Returns | ||
------- | ||
result: relay.Expr | ||
The resized result. | ||
""" | ||
return _make.resize(data, size, layout, method, align_corners) |
Oops, something went wrong.