Skip to content

Commit 31d830d

Browse files
tink2123shanyi15
authored andcommitted
refine image_resize annotation (#15976)
* fix image_resize annotation test=develop * fix some typo * Update nn.py * Update interpolate_op.cc test=develop
1 parent 6d5a04c commit 31d830d

File tree

2 files changed

+93
-91
lines changed

2 files changed

+93
-91
lines changed

paddle/fluid/operators/interpolate_op.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ class InterpolateOpMaker : public framework::OpProtoAndCheckerMaker {
8484
.SetDefault("bilinear");
8585
AddAttr<bool>(
8686
"align_corners",
87-
"an optinal bool. Defaults to True. "
87+
"an optional bool. Defaults to True. "
8888
"If True, the centers of 4 corner pixels of the input and output "
8989
"tensors are aligned, preserving the values at the corner pixels, "
90-
"if Flase, are not aligned")
90+
"If False, are not aligned")
9191
.SetDefault(true);
9292
AddAttr<int>("align_mode",
93-
"(int, default \'1\'), optional for bilinear interpolation"
93+
"(int, default \'1\'), optional for bilinear interpolation, "
9494
"can be \'0\' for src_idx = scale*(dst_indx+0.5)-0.5 , "
9595
"can be \'1\' for src_idx = scale*dst_index .")
9696
.SetDefault(1);

python/paddle/fluid/layers/nn.py

Lines changed: 90 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -6844,56 +6844,58 @@ def image_resize(input,
68446844
68456845
Example:
68466846
6847-
For scale:
6848-
6849-
if align_corners = True && out_size > 1 :
6847+
.. code-block:: text
68506848
6851-
scale_factor = (in_size-1.0)/(out_size-1.0)
6852-
6853-
else:
6849+
For scale:
68546850
6855-
scale_factor = float(in_size/out_size)
6856-
6857-
6858-
Nearest neighbor interpolation:
6859-
6860-
if:
6861-
align_corners = False
6851+
if align_corners = True && out_size > 1 :
68626852
6863-
input : (N,C,H_in,W_in)
6864-
output: (N,C,H_out,W_out) where:
6853+
scale_factor = (in_size-1.0)/(out_size-1.0)
6854+
6855+
else:
6856+
6857+
scale_factor = float(in_size/out_size)
6858+
6859+
6860+
Nearest neighbor interpolation:
6861+
6862+
if:
6863+
align_corners = False
68656864
6866-
H_out = \left \lfloor {H_{in} * scale_{}factor}} \right \rfloor
6867-
W_out = \left \lfloor {W_{in} * scale_{}factor}} \right \rfloor
6865+
input : (N,C,H_in,W_in)
6866+
output: (N,C,H_out,W_out) where:
68686867
6869-
else:
6870-
align_corners = True
6868+
H_out = floor (H_{in} * scale_{factor})
6869+
W_out = floor (W_{in} * scale_{factor})
68716870
6872-
input : (N,C,H_in,W_in)
6873-
output: (N,C,H_out,W_out) where:
6871+
else:
6872+
align_corners = True
68746873
6875-
H_out = round(H_{in} * scale_{factor})
6876-
W_out = round(W_{in} * scale_{factor})
6874+
input : (N,C,H_in,W_in)
6875+
output: (N,C,H_out,W_out) where:
68776876
6878-
Bilinear interpolation:
6877+
H_out = round(H_{in} * scale_{factor})
6878+
W_out = round(W_{in} * scale_{factor})
68796879
6880-
if:
6881-
align_corners = False , align_mode = 0
6882-
6883-
input : (N,C,H_in,W_in)
6884-
output: (N,C,H_out,W_out) where:
6885-
6886-
H_out = (H_{in}+0.5) * scale_{factor} - 0.5
6887-
W_out = (W_{in}+0.5) * scale_{factor} - 0.5
6880+
Bilinear interpolation:
6881+
6882+
if:
6883+
align_corners = False , align_mode = 0
6884+
6885+
input : (N,C,H_in,W_in)
6886+
output: (N,C,H_out,W_out) where:
6887+
6888+
H_out = (H_{in}+0.5) * scale_{factor} - 0.5
6889+
W_out = (W_{in}+0.5) * scale_{factor} - 0.5
68886890
68896891
6890-
else:
6891-
6892-
input : (N,C,H_in,W_in)
6893-
output: (N,C,H_out,W_out) where:
6892+
else:
6893+
6894+
input : (N,C,H_in,W_in)
6895+
output: (N,C,H_out,W_out) where:
68946896
6895-
H_out = H_{in} * scale_{factor}
6896-
W_out = W_{in} * scale_{factor}
6897+
H_out = H_{in} * scale_{factor}
6898+
W_out = W_{in} * scale_{factor}
68976899
68986900
For details of nearest neighbor interpolation, please refer to Wikipedia:
68996901
https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation.
@@ -7048,41 +7050,39 @@ def resize_bilinear(input,
70487050
Align_corners and align_mode are optinal parameters,the calculation
70497051
method of interpolation can be selected by them.
70507052
7051-
7052-
Align_corners and align_mode are optinal parameters,the calculation method
7053-
of interpolation can be selected by them.
7054-
70557053
Example:
70567054
7057-
For scale:
7058-
7059-
if align_corners = True && out_size > 1 :
7055+
.. code-block:: text
70607056
7061-
scale_factor = (in_size-1.0)/(out_size-1.0)
7062-
7063-
else:
7057+
For scale:
70647058
7065-
scale_factor = float(in_size/out_size)
7059+
if align_corners = True && out_size > 1 :
70667060
7067-
Bilinear interpolation:
7061+
scale_factor = (in_size-1.0)/(out_size-1.0)
7062+
7063+
else:
7064+
7065+
scale_factor = float(in_size/out_size)
70687066
7069-
if:
7070-
align_corners = False , align_mode = 0
7071-
7072-
input : (N,C,H_in,W_in)
7073-
output: (N,C,H_out,W_out) where:
7074-
7075-
H_out = (H_{in}+0.5) * scale_{factor} - 0.5
7076-
W_out = (W_{in}+0.5) * scale_{factor} - 0.5
7067+
Bilinear interpolation:
7068+
7069+
if:
7070+
align_corners = False , align_mode = 0
7071+
7072+
input : (N,C,H_in,W_in)
7073+
output: (N,C,H_out,W_out) where:
7074+
7075+
H_out = (H_{in}+0.5) * scale_{factor} - 0.5
7076+
W_out = (W_{in}+0.5) * scale_{factor} - 0.5
70777077
70787078
7079-
else:
7079+
else:
70807080
7081-
input : (N,C,H_in,W_in)
7082-
output: (N,C,H_out,W_out) where:
7081+
input : (N,C,H_in,W_in)
7082+
output: (N,C,H_out,W_out) where:
70837083
7084-
H_out = H_{in} * scale_{factor}
7085-
W_out = W_{in} * scale_{factor}
7084+
H_out = H_{in} * scale_{factor}
7085+
W_out = W_{in} * scale_{factor}
70867086
70877087
70887088
@@ -7134,42 +7134,44 @@ def resize_nearest(input,
71347134
align_corners=True):
71357135
"""
71367136
Resize input by performing nearest neighbor interpolation in both the
7137-
3rd dimention(in height direction) and the 4th dimention(in width
7138-
direction) based on given output shape which specified by actual_shape,
7137+
3rd dimension(in height direction) and the 4th dimension(in width
7138+
direction) based on given output shape which is specified by actual_shape,
71397139
out_shape and scale in priority order.
71407140
71417141
Example:
71427142
7143-
For scale:
7144-
7145-
if align_corners = True && out_size > 1 :
7143+
.. code-block:: text
7144+
7145+
For scale:
7146+
7147+
if align_corners = True && out_size > 1 :
71467148
7147-
scale_factor = (in_size-1.0)/(out_size-1.0)
7148-
7149-
else:
7149+
scale_factor = (in_size-1.0)/(out_size-1.0)
7150+
7151+
else:
7152+
7153+
scale_factor = float(in_size/out_size)
7154+
7155+
7156+
Nearest neighbor interpolation:
71507157
7151-
scale_factor = float(in_size/out_size)
7152-
7153-
7154-
Nearest neighbor interpolation:
7155-
7156-
if:
7157-
align_corners = False
7158+
if:
7159+
align_corners = False
71587160
7159-
input : (N,C,H_in,W_in)
7160-
output: (N,C,H_out,W_out) where:
7161+
input : (N,C,H_in,W_in)
7162+
output: (N,C,H_out,W_out) where:
71617163
7162-
H_out = \left \lfloor {H_{in} * scale_{}factor}} \right \rfloor
7163-
W_out = \left \lfloor {W_{in} * scale_{}factor}} \right \rfloor
7164+
H_out = floor(H_{in} * scale_{factor})
7165+
W_out = floor(W_{in} * scale_{factor})
71647166
7165-
else:
7166-
align_corners = True
7167+
else:
7168+
align_corners = True
71677169
7168-
input : (N,C,H_in,W_in)
7169-
output: (N,C,H_out,W_out) where:
7170+
input : (N,C,H_in,W_in)
7171+
output: (N,C,H_out,W_out) where:
71707172
7171-
H_out = round(H_{in} * scale_{factor})
7172-
W_out = round(W_{in} * scale_{factor})
7173+
H_out = round(H_{in} * scale_{factor})
7174+
W_out = round(W_{in} * scale_{factor})
71737175
71747176
71757177
For details of nearest neighbor interpolation, please refer to Wikipedia:

0 commit comments

Comments
 (0)