Skip to content

Commit

Permalink
refine image_resize annotation (PaddlePaddle#15976)
Browse files Browse the repository at this point in the history
* fix image_resize annotation

test=develop

* fix some typo

* Update nn.py

* Update interpolate_op.cc

test=develop
  • Loading branch information
tink2123 authored and shanyi15 committed Mar 1, 2019
1 parent 6d5a04c commit 31d830d
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 91 deletions.
6 changes: 3 additions & 3 deletions paddle/fluid/operators/interpolate_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class InterpolateOpMaker : public framework::OpProtoAndCheckerMaker {
.SetDefault("bilinear");
AddAttr<bool>(
"align_corners",
"an optinal bool. Defaults to True. "
"an optional bool. Defaults to True. "
"If True, the centers of 4 corner pixels of the input and output "
"tensors are aligned, preserving the values at the corner pixels, "
"if Flase, are not aligned")
"If False, are not aligned")
.SetDefault(true);
AddAttr<int>("align_mode",
"(int, default \'1\'), optional for bilinear interpolation"
"(int, default \'1\'), optional for bilinear interpolation, "
"can be \'0\' for src_idx = scale*(dst_indx+0.5)-0.5 , "
"can be \'1\' for src_idx = scale*dst_index .")
.SetDefault(1);
Expand Down
178 changes: 90 additions & 88 deletions python/paddle/fluid/layers/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6844,56 +6844,58 @@ def image_resize(input,
Example:
For scale:
if align_corners = True && out_size > 1 :
.. code-block:: text
scale_factor = (in_size-1.0)/(out_size-1.0)
else:
For scale:
scale_factor = float(in_size/out_size)
Nearest neighbor interpolation:
if:
align_corners = False
if align_corners = True && out_size > 1 :
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
scale_factor = (in_size-1.0)/(out_size-1.0)
else:
scale_factor = float(in_size/out_size)
Nearest neighbor interpolation:
if:
align_corners = False
H_out = \left \lfloor {H_{in} * scale_{}factor}} \right \rfloor
W_out = \left \lfloor {W_{in} * scale_{}factor}} \right \rfloor
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
else:
align_corners = True
H_out = floor (H_{in} * scale_{factor})
W_out = floor (W_{in} * scale_{factor})
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
else:
align_corners = True
H_out = round(H_{in} * scale_{factor})
W_out = round(W_{in} * scale_{factor})
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
Bilinear interpolation:
H_out = round(H_{in} * scale_{factor})
W_out = round(W_{in} * scale_{factor})
if:
align_corners = False , align_mode = 0
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = (H_{in}+0.5) * scale_{factor} - 0.5
W_out = (W_{in}+0.5) * scale_{factor} - 0.5
Bilinear interpolation:
if:
align_corners = False , align_mode = 0
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = (H_{in}+0.5) * scale_{factor} - 0.5
W_out = (W_{in}+0.5) * scale_{factor} - 0.5
else:
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
else:
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = H_{in} * scale_{factor}
W_out = W_{in} * scale_{factor}
H_out = H_{in} * scale_{factor}
W_out = W_{in} * scale_{factor}
For details of nearest neighbor interpolation, please refer to Wikipedia:
https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation.
Expand Down Expand Up @@ -7048,41 +7050,39 @@ def resize_bilinear(input,
Align_corners and align_mode are optinal parameters,the calculation
method of interpolation can be selected by them.
Align_corners and align_mode are optinal parameters,the calculation method
of interpolation can be selected by them.
Example:
For scale:
if align_corners = True && out_size > 1 :
.. code-block:: text
scale_factor = (in_size-1.0)/(out_size-1.0)
else:
For scale:
scale_factor = float(in_size/out_size)
if align_corners = True && out_size > 1 :
Bilinear interpolation:
scale_factor = (in_size-1.0)/(out_size-1.0)
else:
scale_factor = float(in_size/out_size)
if:
align_corners = False , align_mode = 0
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = (H_{in}+0.5) * scale_{factor} - 0.5
W_out = (W_{in}+0.5) * scale_{factor} - 0.5
Bilinear interpolation:
if:
align_corners = False , align_mode = 0
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = (H_{in}+0.5) * scale_{factor} - 0.5
W_out = (W_{in}+0.5) * scale_{factor} - 0.5
else:
else:
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = H_{in} * scale_{factor}
W_out = W_{in} * scale_{factor}
H_out = H_{in} * scale_{factor}
W_out = W_{in} * scale_{factor}
Expand Down Expand Up @@ -7134,42 +7134,44 @@ def resize_nearest(input,
align_corners=True):
"""
Resize input by performing nearest neighbor interpolation in both the
3rd dimention(in height direction) and the 4th dimention(in width
direction) based on given output shape which specified by actual_shape,
3rd dimension(in height direction) and the 4th dimension(in width
direction) based on given output shape which is specified by actual_shape,
out_shape and scale in priority order.
Example:
For scale:
if align_corners = True && out_size > 1 :
.. code-block:: text
For scale:
if align_corners = True && out_size > 1 :
scale_factor = (in_size-1.0)/(out_size-1.0)
else:
scale_factor = (in_size-1.0)/(out_size-1.0)
else:
scale_factor = float(in_size/out_size)
Nearest neighbor interpolation:
scale_factor = float(in_size/out_size)
Nearest neighbor interpolation:
if:
align_corners = False
if:
align_corners = False
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = \left \lfloor {H_{in} * scale_{}factor}} \right \rfloor
W_out = \left \lfloor {W_{in} * scale_{}factor}} \right \rfloor
H_out = floor(H_{in} * scale_{factor})
W_out = floor(W_{in} * scale_{factor})
else:
align_corners = True
else:
align_corners = True
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
input : (N,C,H_in,W_in)
output: (N,C,H_out,W_out) where:
H_out = round(H_{in} * scale_{factor})
W_out = round(W_{in} * scale_{factor})
H_out = round(H_{in} * scale_{factor})
W_out = round(W_{in} * scale_{factor})
For details of nearest neighbor interpolation, please refer to Wikipedia:
Expand Down

0 comments on commit 31d830d

Please sign in to comment.