interpolate
注意: 参数 actual_shape
将被弃用,请使用 out_shape
替代。
该OP用于调整一个batch中图片的大小。
输入为4-D Tensor时形状为(num_batches, channels, in_h, in_w)或者(num_batches, in_h, in_w, channels),输入为5-D Tensor时形状为(num_batches, channels, in_d, in_h, in_w)或者(num_batches, in_d, in_h, in_w, channels),并且调整大小只适用于深度,高度和宽度对应的维度。
支持的插值方法:
最近邻插值是在输入张量的高度和宽度上进行最近邻插值。
双线性插值是线性插值的扩展,用于在直线2D网格上插值两个变量(例如,该操作中的H方向和W方向)的函数。 关键思想是首先在一个方向上执行线性插值,然后在另一个方向上再次执行线性插值。
三线插值是线性插值的一种扩展,是3参数的插值方程(比如op里的D,H,W方向),在三个方向上进行线性插值。
双三次插值是在二维网格上对数据点进行插值的三次插值的扩展,它能创造出比双线性和最近临插值更为光滑的图像边缘。
align_corners和align_mode是可选参数,插值的计算方法可以由它们选择。
有关最近邻插值的详细信息,请参阅维基百科: 最近邻插值
有关双线性插值的详细信息,请参阅维基百科:
有关三线插值的详细信息,请参阅维基百科: 三线插值
有关双三次插值的详细信息,请参阅维基百科:
4-D Tensor,形状为 (num_batches, channels, out_h, out_w) 或 (num_batches, out_h, out_w, channels);或者5-D Tensor,形状为 (num_batches, channels, out_d, out_h, out_w) 或 (num_batches, out_d, out_h, out_w, channels)。
变量(variable)
#declarative mode
import paddle
import numpy as np
input = fluid.data(name="input", shape=[None,3,6,10])
# example 1
output = fluid.layers.interpolate(input=input,out_shape=[12,12])
# example 2
# x = np.array([2]).astype("int32")
# dim1 = fluid.data(name="dim1", shape=[1], dtype="int32")
# fluid.layers.assign(input=x, output=dim1)
# output = fluid.layers.interpolate(input=input,out_shape=[12,dim1])
# example 3
# x = np.array([3,12]).astype("int32")
# shape_tensor = fluid.data(name="shape_tensor", shape=[2], dtype="int32")
# fluid.layers.assign(input=x, output=shape_tensor)
# output = pfluid.layers.interpolate(input=input,out_shape=shape_tensor)
# example 4
# x = np.array([0.5]).astype("float32")
# scale_tensor = fluid.data(name="scale", shape=[1], dtype="float32")
# fluid.layers.assign(x,scale_tensor)
# output = fluid.layers.interpolate(input=input,scale=scale_tensor)
place = fluid.CPUPlace()
exe.run(fluid.default_startup_program())
output_data = exe.run(fluid.default_main_program(),
feed={"input":input_data},
fetch_list=[output],
return_numpy=True)
print(output_data[0].shape)
# example 1
# (2, 3, 12, 12)
# example 2
# (2, 3, 12, 2)
# example 3
# (2, 3, 3, 12)
# example 4
# (2, 3, 3, 5)
#imperative mode
import paddle.fluid.dygraph as dg
import paddle.fluid as fluid
with dg.guard(place) as g:
input = dg.to_variable(input_data)
output = fluid.layers.interpolate(input=input, out_shape=[12,12])
print(output.shape)