|
|
|
@ -6606,7 +6606,12 @@ def label_smooth(label,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@templatedoc()
|
|
|
|
@templatedoc()
|
|
|
|
def roi_pool(input, rois, pooled_height=1, pooled_width=1, spatial_scale=1.0):
|
|
|
|
def roi_pool(input,
|
|
|
|
|
|
|
|
rois,
|
|
|
|
|
|
|
|
pooled_height=1,
|
|
|
|
|
|
|
|
pooled_width=1,
|
|
|
|
|
|
|
|
spatial_scale=1.0,
|
|
|
|
|
|
|
|
rois_lod=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This operator implements the roi_pooling layer.
|
|
|
|
This operator implements the roi_pooling layer.
|
|
|
|
Region of interest pooling (also known as RoI pooling) is to perform max pooling on inputs of nonuniform sizes to obtain fixed-size feature maps (e.g. 7*7).
|
|
|
|
Region of interest pooling (also known as RoI pooling) is to perform max pooling on inputs of nonuniform sizes to obtain fixed-size feature maps (e.g. 7*7).
|
|
|
|
@ -6622,6 +6627,7 @@ def roi_pool(input, rois, pooled_height=1, pooled_width=1, spatial_scale=1.0):
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
input (Variable): Input feature, 4D-Tensor with the shape of [N,C,H,W], where N is the batch size, C is the input channel, H is Height, W is weight. The data type is float32 or float64.
|
|
|
|
input (Variable): Input feature, 4D-Tensor with the shape of [N,C,H,W], where N is the batch size, C is the input channel, H is Height, W is weight. The data type is float32 or float64.
|
|
|
|
rois (Variable): ROIs (Regions of Interest) to pool over. 2D-LoDTensor with the shape of [num_rois,4], the lod level is 1. Given as [[x1, y1, x2, y2], ...], (x1, y1) is the top left coordinates, and (x2, y2) is the bottom right coordinates.
|
|
|
|
rois (Variable): ROIs (Regions of Interest) to pool over. 2D-LoDTensor with the shape of [num_rois,4], the lod level is 1. Given as [[x1, y1, x2, y2], ...], (x1, y1) is the top left coordinates, and (x2, y2) is the bottom right coordinates.
|
|
|
|
|
|
|
|
rois_lod (Variable): The lod info of rois. Default: None
|
|
|
|
pooled_height (int, optional): The pooled output height, data type is int32. Default: 1
|
|
|
|
pooled_height (int, optional): The pooled output height, data type is int32. Default: 1
|
|
|
|
pooled_width (int, optional): The pooled output height, data type is int32. Default: 1
|
|
|
|
pooled_width (int, optional): The pooled output height, data type is int32. Default: 1
|
|
|
|
spatial_scale (float, optional): Multiplicative spatial scale factor to translate ROI coords from their input scale to the scale used when pooling. Default: 1.0
|
|
|
|
spatial_scale (float, optional): Multiplicative spatial scale factor to translate ROI coords from their input scale to the scale used when pooling. Default: 1.0
|
|
|
|
@ -6644,19 +6650,22 @@ def roi_pool(input, rois, pooled_height=1, pooled_width=1, spatial_scale=1.0):
|
|
|
|
|
|
|
|
|
|
|
|
input_data = np.array([i for i in range(1,17)]).reshape(1,1,4,4).astype(DATATYPE)
|
|
|
|
input_data = np.array([i for i in range(1,17)]).reshape(1,1,4,4).astype(DATATYPE)
|
|
|
|
roi_data =fluid.create_lod_tensor(np.array([[1., 1., 2., 2.], [1.5, 1.5, 3., 3.]]).astype(DATATYPE),[[2]], place)
|
|
|
|
roi_data =fluid.create_lod_tensor(np.array([[1., 1., 2., 2.], [1.5, 1.5, 3., 3.]]).astype(DATATYPE),[[2]], place)
|
|
|
|
|
|
|
|
rois_lod_data = np.array([0, 2])
|
|
|
|
|
|
|
|
|
|
|
|
x = fluid.data(name='input', shape=[None,1,4,4], dtype=DATATYPE)
|
|
|
|
x = fluid.data(name='input', shape=[None,1,4,4], dtype=DATATYPE)
|
|
|
|
rois = fluid.data(name='roi', shape=[None,4], dtype=DATATYPE)
|
|
|
|
rois = fluid.data(name='roi', shape=[None,4], dtype=DATATYPE)
|
|
|
|
|
|
|
|
rois_lod = fluid.data(name='rois_lod', shape=[None], dtype='int64')
|
|
|
|
|
|
|
|
|
|
|
|
pool_out = fluid.layers.roi_pool(
|
|
|
|
pool_out = fluid.layers.roi_pool(
|
|
|
|
input=x,
|
|
|
|
input=x,
|
|
|
|
rois=rois,
|
|
|
|
rois=rois,
|
|
|
|
pooled_height=1,
|
|
|
|
pooled_height=1,
|
|
|
|
pooled_width=1,
|
|
|
|
pooled_width=1,
|
|
|
|
spatial_scale=1.0)
|
|
|
|
spatial_scale=1.0,
|
|
|
|
|
|
|
|
rois_lod=rois_lod)
|
|
|
|
|
|
|
|
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
exe = fluid.Executor(place)
|
|
|
|
out, = exe.run(feed={'input':input_data ,'roi':roi_data}, fetch_list=[pool_out.name])
|
|
|
|
out, = exe.run(feed={'input':input_data ,'roi':roi_data, 'rois_lod': rois_lod_data}, fetch_list=[pool_out.name])
|
|
|
|
print(out) #array([[[[11.]]], [[[16.]]]], dtype=float32)
|
|
|
|
print(out) #array([[[[11.]]], [[[16.]]]], dtype=float32)
|
|
|
|
print(np.array(out).shape) # (2, 1, 1, 1)
|
|
|
|
print(np.array(out).shape) # (2, 1, 1, 1)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@ -6667,7 +6676,8 @@ def roi_pool(input, rois, pooled_height=1, pooled_width=1, spatial_scale=1.0):
|
|
|
|
helper.append_op(
|
|
|
|
helper.append_op(
|
|
|
|
type="roi_pool",
|
|
|
|
type="roi_pool",
|
|
|
|
inputs={"X": input,
|
|
|
|
inputs={"X": input,
|
|
|
|
"ROIs": rois},
|
|
|
|
"ROIs": rois,
|
|
|
|
|
|
|
|
"RoisLod": rois_lod},
|
|
|
|
outputs={"Out": pool_out,
|
|
|
|
outputs={"Out": pool_out,
|
|
|
|
"Argmax": argmaxes},
|
|
|
|
"Argmax": argmaxes},
|
|
|
|
attrs={
|
|
|
|
attrs={
|
|
|
|
@ -6685,7 +6695,8 @@ def roi_align(input,
|
|
|
|
pooled_width=1,
|
|
|
|
pooled_width=1,
|
|
|
|
spatial_scale=1.0,
|
|
|
|
spatial_scale=1.0,
|
|
|
|
sampling_ratio=-1,
|
|
|
|
sampling_ratio=-1,
|
|
|
|
name=None):
|
|
|
|
name=None,
|
|
|
|
|
|
|
|
rois_lod=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
${comment}
|
|
|
|
${comment}
|
|
|
|
|
|
|
|
|
|
|
|
@ -6696,6 +6707,7 @@ def roi_align(input,
|
|
|
|
data type is float32 or float64. Given as [[x1, y1, x2, y2], ...],
|
|
|
|
data type is float32 or float64. Given as [[x1, y1, x2, y2], ...],
|
|
|
|
(x1, y1) is the top left coordinates, and (x2, y2) is the bottom
|
|
|
|
(x1, y1) is the top left coordinates, and (x2, y2) is the bottom
|
|
|
|
right coordinates.
|
|
|
|
right coordinates.
|
|
|
|
|
|
|
|
rois_lod (Variable): The lod info of rois. Default: None
|
|
|
|
pooled_height (int32, optional): ${pooled_height_comment} Default: 1
|
|
|
|
pooled_height (int32, optional): ${pooled_height_comment} Default: 1
|
|
|
|
pooled_width (int32, optional): ${pooled_width_comment} Default: 1
|
|
|
|
pooled_width (int32, optional): ${pooled_width_comment} Default: 1
|
|
|
|
spatial_scale (float32, optional): ${spatial_scale_comment} Default: 1.0
|
|
|
|
spatial_scale (float32, optional): ${spatial_scale_comment} Default: 1.0
|
|
|
|
@ -6718,12 +6730,14 @@ def roi_align(input,
|
|
|
|
name='data', shape=[None, 256, 32, 32], dtype='float32')
|
|
|
|
name='data', shape=[None, 256, 32, 32], dtype='float32')
|
|
|
|
rois = fluid.data(
|
|
|
|
rois = fluid.data(
|
|
|
|
name='rois', shape=[None, 4], dtype='float32')
|
|
|
|
name='rois', shape=[None, 4], dtype='float32')
|
|
|
|
|
|
|
|
rois_lod = fluid.data(name='rois_lod', shape=[None], dtype='int64')
|
|
|
|
align_out = fluid.layers.roi_align(input=x,
|
|
|
|
align_out = fluid.layers.roi_align(input=x,
|
|
|
|
rois=rois,
|
|
|
|
rois=rois,
|
|
|
|
pooled_height=7,
|
|
|
|
pooled_height=7,
|
|
|
|
pooled_width=7,
|
|
|
|
pooled_width=7,
|
|
|
|
spatial_scale=0.5,
|
|
|
|
spatial_scale=0.5,
|
|
|
|
sampling_ratio=-1)
|
|
|
|
sampling_ratio=-1,
|
|
|
|
|
|
|
|
rois_lod=rois_lod)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
check_variable_and_dtype(input, 'input', ['float32', 'float64'],
|
|
|
|
check_variable_and_dtype(input, 'input', ['float32', 'float64'],
|
|
|
|
'roi_align')
|
|
|
|
'roi_align')
|
|
|
|
@ -6734,7 +6748,8 @@ def roi_align(input,
|
|
|
|
helper.append_op(
|
|
|
|
helper.append_op(
|
|
|
|
type="roi_align",
|
|
|
|
type="roi_align",
|
|
|
|
inputs={"X": input,
|
|
|
|
inputs={"X": input,
|
|
|
|
"ROIs": rois},
|
|
|
|
"ROIs": rois,
|
|
|
|
|
|
|
|
"RoisLod": rois_lod},
|
|
|
|
outputs={"Out": align_out},
|
|
|
|
outputs={"Out": align_out},
|
|
|
|
attrs={
|
|
|
|
attrs={
|
|
|
|
"pooled_height": pooled_height,
|
|
|
|
"pooled_height": pooled_height,
|
|
|
|
|