提交 0d29e659 编写于 作者: Y yuyang18

Add resize_bilinear

上级 439a2657
...@@ -56,17 +56,16 @@ class BilinearInterpOpMaker : public framework::OpProtoAndCheckerMaker { ...@@ -56,17 +56,16 @@ class BilinearInterpOpMaker : public framework::OpProtoAndCheckerMaker {
public: public:
void Make() override { void Make() override {
AddInput("X", AddInput("X",
"(Tensor) The input tensor of bilinear interpolation, " "The input tensor of bilinear interpolation, "
"This is a 4-D tensor with shape of (N x C x h x w)"); "This is a 4-D tensor with shape of (N x C x h x w)");
AddInput("OutSize", AddInput("OutSize",
"(Tensor) This is a 1-D tensor with two number. " "This is a 1-D tensor with two number. "
"The first number is height and the second number is width.") "The first number is height and the second number is width.")
.AsDispensable(); .AsDispensable();
AddOutput("Out", AddOutput("Out", "The dimension of output is (N x C x out_h x out_w)");
"(Tensor) The dimension of output is (N x C x out_h x out_w]");
AddAttr<int>("out_h", "(int) output height of bilinear interpolation op."); AddAttr<int>("out_h", "output height of bilinear interpolation op.");
AddAttr<int>("out_w", "(int) output width of bilinear interpolation op."); AddAttr<int>("out_w", "output width of bilinear interpolation op.");
AddComment(R"DOC( AddComment(R"DOC(
Bilinear interpolation is an extension of linear interpolation for Bilinear interpolation is an extension of linear interpolation for
interpolating functions of two variables (e.g. H-direction and interpolating functions of two variables (e.g. H-direction and
......
...@@ -224,7 +224,7 @@ def autodoc(comment=""): ...@@ -224,7 +224,7 @@ def autodoc(comment=""):
return __impl__ return __impl__
def templatedoc(): def templatedoc(op_type=None):
""" """
Decorator of layer function. It will use the docstring from the layer Decorator of layer function. It will use the docstring from the layer
function as the template. The template arguments are: function as the template. The template arguments are:
...@@ -242,15 +242,20 @@ def templatedoc(): ...@@ -242,15 +242,20 @@ def templatedoc():
return msg.rstrip('.') return msg.rstrip('.')
def __impl__(func): def __impl__(func):
op_proto = OpProtoHolder.instance().get_op_proto(func.__name__) if op_type is None:
op_type_name = func.__name__
else:
op_type_name = op_type
op_proto = OpProtoHolder.instance().get_op_proto(op_type_name)
tmpl = string.Template(func.__doc__) tmpl = string.Template(func.__doc__)
comment_lines = op_proto.comment.split("\n") comment_lines = op_proto.comment.split("\n")
comment = "" comment = ""
for line in comment_lines: for line in comment_lines:
line = line.lstrip() line = line.strip()
if len(line) != 0:
comment += line comment += line
comment += "\n" comment += " "
args = {"comment": trim_ending_dot(comment)} args = {"comment": trim_ending_dot(comment)}
for each_input in op_proto.inputs: for each_input in op_proto.inputs:
......
...@@ -4037,18 +4037,25 @@ def image_resize(input, ...@@ -4037,18 +4037,25 @@ def image_resize(input,
return out return out
@templatedoc(op_type="bilinear_interp")
def resize_bilinear(input, out_shape=None, scale=None, name=None): def resize_bilinear(input, out_shape=None, scale=None, name=None):
""" """
This is an alias of layer 'image_resize' with bilinear interpolation. ${comment}
Args:
input(${x_type}): ${x_comment}.
out_shape(${out_size_type}): ${out_size_comment}.
The mathematical meaning of resize bilinear layer is scale(float|None): The multiplier for the input height or width. At
Bilinear interpolation. least one of out_shape or scale must be set. And out_shape has
Bilinear interpolation is an extension of linear interpolation for a higher priority than scale. Default: None.
interpolating functions of two variables (e.g. H-direction and
W-direction in this layer) on a rectilinear 2D grid. name(str|None): The output variable name.
Returns:
For details, please refer to Wikipedia: ${out_comment}.
https://en.wikipedia.org/wiki/Bilinear_interpolation
""" """
return image_resize(input, out_shape, scale, name, 'BILINEAR') return image_resize(input, out_shape, scale, name, 'BILINEAR')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册