提交 2b8f082b authored 作者: erakra's avatar erakra

small simplification

上级 c15f3f14
...@@ -1761,8 +1761,7 @@ def bilinear_kernel_1D(ratio, normalize=True): ...@@ -1761,8 +1761,7 @@ def bilinear_kernel_1D(ratio, normalize=True):
def frac_bilinear_upsampling(input, def frac_bilinear_upsampling(input,
ratio=None, frac_ratio):
frac_ratio=None):
"""Compute bilinear upsampling """Compute bilinear upsampling
This function will build the symbolic graph for upsampling This function will build the symbolic graph for upsampling
a tensor by the given ratio using bilinear interpolation. a tensor by the given ratio using bilinear interpolation.
...@@ -1772,10 +1771,7 @@ def frac_bilinear_upsampling(input, ...@@ -1772,10 +1771,7 @@ def frac_bilinear_upsampling(input,
input: symbolic 4D tensor input: symbolic 4D tensor
mini-batch of feature map stacks, of shape (batch size, mini-batch of feature map stacks, of shape (batch size,
input channels, input rows, input columns) that will be upsampled. input channels, input rows, input columns) that will be upsampled.
ratio: `int or Constant or Scalar Tensor of int* dtype` frac_ratio: tuple of int or tuple of tuples of int
the ratio by which the input is upsampled in the 2D space (row and
col size).
frac_ratio: None, tuple of int or tuple of tuples of int
The tuple defining the fractional ratio by which the input is The tuple defining the fractional ratio by which the input is
upsampled in the 2D space. One fractional ratio should be upsampled in the 2D space. One fractional ratio should be
represented as (numerator, denominator). If row and col ratios are represented as (numerator, denominator). If row and col ratios are
...@@ -1790,24 +1786,17 @@ def frac_bilinear_upsampling(input, ...@@ -1790,24 +1786,17 @@ def frac_bilinear_upsampling(input,
Notes Notes
----- -----
:note: The kernel used for bilinear interpolation is fixed (not learned). :note: The kernel used for bilinear interpolation is fixed (not learned).
:note: When the upsampling ratio is even, the last row and column is :note: When the upsampling frac_ratio numerator is even, the
repeated one extra time compared to the first row and column which makes last row and column is repeated one extra time compared to the first
the upsampled tensor asymmetrical on both sides. This does not happen when row and column which makes the upsampled tensor asymmetrical on both
the upsampling ratio is odd. sides. This does not happen when it is odd.
:note: This function must get either ratio or frac_ratio as parameter and
never both at once.
""" """
T = theano.tensor T = theano.tensor
row, col = input.shape[2:] row, col = input.shape[2:]
up_input = input.reshape((-1, 1, row, col)) up_input = input.reshape((-1, 1, row, col))
# redefince the ratio depending on the case # defince the upsampling ratio depending on the case
if frac_ratio is None:
if not isinstance(ratio, tuple):
ratio = (ratio, ratio)
subsample = (1, 1)
else:
if not isinstance(frac_ratio, tuple): if not isinstance(frac_ratio, tuple):
raise ValueError("frac_ratio must be a tuple") raise ValueError("frac_ratio must be a tuple")
else: else:
...@@ -1914,12 +1903,10 @@ def bilinear_upsampling(input, ...@@ -1914,12 +1903,10 @@ def bilinear_upsampling(input,
if frac_ratio: if frac_ratio:
if use_1D_kernel: if use_1D_kernel:
raise ValueError('For fractional ratios 1D kernel' raise ValueError('For fractional ratios 1D kernel '
'method not implemented. You may want to pass ' 'method not implemented. You may want to pass '
'use_1D_kernel as False') 'use_1D_kernel as False')
return frac_bilinear_upsampling(input, return frac_bilinear_upsampling(input, frac_ratio=frac_ratio)
ratio=ratio,
frac_ratio=frac_ratio)
# the remaining case if integer ratio with use_1D_kernel # the remaining case if integer ratio with use_1D_kernel
T = theano.tensor T = theano.tensor
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论