Skip to content

Commit 0d29e65

Browse files
committed
Add resize_bilinear
1 parent 439a265 commit 0d29e65

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

paddle/fluid/operators/bilinear_interp_op.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,16 @@ class BilinearInterpOpMaker : public framework::OpProtoAndCheckerMaker {
5656
public:
5757
void Make() override {
5858
AddInput("X",
59-
"(Tensor) The input tensor of bilinear interpolation, "
59+
"The input tensor of bilinear interpolation, "
6060
"This is a 4-D tensor with shape of (N x C x h x w)");
6161
AddInput("OutSize",
62-
"(Tensor) This is a 1-D tensor with two number. "
62+
"This is a 1-D tensor with two number. "
6363
"The first number is height and the second number is width.")
6464
.AsDispensable();
65-
AddOutput("Out",
66-
"(Tensor) The dimension of output is (N x C x out_h x out_w]");
65+
AddOutput("Out", "The dimension of output is (N x C x out_h x out_w)");
6766

68-
AddAttr<int>("out_h", "(int) output height of bilinear interpolation op.");
69-
AddAttr<int>("out_w", "(int) output width of bilinear interpolation op.");
67+
AddAttr<int>("out_h", "output height of bilinear interpolation op.");
68+
AddAttr<int>("out_w", "output width of bilinear interpolation op.");
7069
AddComment(R"DOC(
7170
Bilinear interpolation is an extension of linear interpolation for
7271
interpolating functions of two variables (e.g. H-direction and

python/paddle/fluid/layers/layer_function_generator.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def __impl__(func):
224224
return __impl__
225225

226226

227-
def templatedoc():
227+
def templatedoc(op_type=None):
228228
"""
229229
Decorator of layer function. It will use the docstring from the layer
230230
function as the template. The template arguments are:
@@ -242,15 +242,20 @@ def trim_ending_dot(msg):
242242
return msg.rstrip('.')
243243

244244
def __impl__(func):
245-
op_proto = OpProtoHolder.instance().get_op_proto(func.__name__)
245+
if op_type is None:
246+
op_type_name = func.__name__
247+
else:
248+
op_type_name = op_type
249+
op_proto = OpProtoHolder.instance().get_op_proto(op_type_name)
246250
tmpl = string.Template(func.__doc__)
247251

248252
comment_lines = op_proto.comment.split("\n")
249253
comment = ""
250254
for line in comment_lines:
251-
line = line.lstrip()
252-
comment += line
253-
comment += "\n"
255+
line = line.strip()
256+
if len(line) != 0:
257+
comment += line
258+
comment += " "
254259

255260
args = {"comment": trim_ending_dot(comment)}
256261
for each_input in op_proto.inputs:

python/paddle/fluid/layers/nn.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,18 +4037,25 @@ def _is_list_or_turple_(data):
40374037
return out
40384038

40394039

4040+
@templatedoc(op_type="bilinear_interp")
40404041
def resize_bilinear(input, out_shape=None, scale=None, name=None):
40414042
"""
4042-
This is an alias of layer 'image_resize' with bilinear interpolation.
4043+
${comment}
4044+
4045+
Args:
4046+
input(${x_type}): ${x_comment}.
4047+
4048+
out_shape(${out_size_type}): ${out_size_comment}.
40434049
4044-
The mathematical meaning of resize bilinear layer is
4045-
Bilinear interpolation.
4046-
Bilinear interpolation is an extension of linear interpolation for
4047-
interpolating functions of two variables (e.g. H-direction and
4048-
W-direction in this layer) on a rectilinear 2D grid.
4050+
scale(float|None): The multiplier for the input height or width. At
4051+
least one of out_shape or scale must be set. And out_shape has
4052+
a higher priority than scale. Default: None.
4053+
4054+
name(str|None): The output variable name.
4055+
4056+
Returns:
40494057
4050-
For details, please refer to Wikipedia:
4051-
https://en.wikipedia.org/wiki/Bilinear_interpolation
4058+
${out_comment}.
40524059
"""
40534060

40544061
return image_resize(input, out_shape, scale, name, 'BILINEAR')

0 commit comments

Comments
 (0)