-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expose ROI Pooling into Python API. #10169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,7 @@ | |
| 'lrn', | ||
| 'pad', | ||
| 'label_smooth', | ||
| 'roi_pool', | ||
| ] | ||
|
|
||
|
|
||
|
|
@@ -3759,3 +3760,44 @@ def label_smooth(label, | |
| outputs={"Out": smooth_label}, | ||
| attrs={"epsilon": float(epsilon)}) | ||
| return smooth_label | ||
|
|
||
|
|
||
| def roi_pool(input, rois, pooled_height=1, pooled_width=1, spatial_scale=1.0): | ||
| """ | ||
| RoI pooling, its purpose is to perform max pooling on inputs of nonuniform sizes to obtain fixed-size feature maps (e.g. 7*7). | ||
| The operator has three steps: | ||
| 1.Dividing each region proposal into equal-sized sections with the pooled_width and pooled_height | ||
| 2.Finding the largest value in each section | ||
| 3.Copying these max values to the output buffer | ||
|
|
||
| Args: | ||
| input (Variable): The input for roi pooling. | ||
| rois (Variable): ROIs (Regions of Interest) to pool over. It should be a 2-D tensor of shape (num_rois, 5). It given as [[batch_id, x1, y1, x2, y2], ...], where batch_id is the id of the data, (x1, y1) is the top left coordinates, and (x2, y2) is the bottom right coordinates. | ||
| pooled_height (integer): The pooled output height. Default: 1 | ||
| pooled_width (integer): The pooled output width. Default: 1 | ||
| spatial_scale (float): Multiplicative spatial scale factor. To translate ROI coords from their input scale to the scale used when pooling. Default: 1.0 | ||
|
|
||
| Returns: | ||
| pool_out (Variable): The output of ROIPoolOp is a 4-D tensor with shape (num_rois, channels, pooled_h, pooled_w). | ||
| argmaxes (Variable): Argmaxes corresponding to indices in input with shape (num_rois, channels, pooled_h, pooled_w). | ||
|
|
||
| Examples: | ||
| .. code-block:: python | ||
| # assuming we have input x_feas, rois x_rois, pooled_height ph, pooled_width pw and spatial_scale scale. | ||
| pool_out, argmaxes = fluid.layers.roi_pool(input=x_feas, rois=x_rois, pooled_height=ph, pooled_width=pw, spatial_scale=scale) | ||
| """ | ||
| helper = LayerHelper('roi_pool', **locals()) | ||
| dtype = helper.input_dtype() | ||
| pool_out = helper.create_tmp_variable(dtype) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also need to create variable for |
||
| helper.append_op( | ||
| type="pool2d", | ||
| inputs={"X": input, | ||
| "ROIs": rois}, | ||
| outputs={"Out": pool_out, | ||
| "Argmax": argmaxes}, | ||
| attrs={ | ||
| "pooled_height": pooled_height, | ||
| "pooled_width": pooled_width, | ||
| "spatial_scale": spatial_scale | ||
| }) | ||
| return pool_out, argmaxes | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一般
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不需要的 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -359,6 +359,17 @@ def test_topk(self): | |
| self.assertIsNotNone(indices) | ||
| print(str(program)) | ||
|
|
||
| def test_roi_pool(self): | ||
| print("test_roi_pool") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
| program = Program() | ||
| with program_guard(program): | ||
| x = layers.data(name="x", shape=[10, 256, 30, 30], dtype="float32") | ||
| rois = layers.data(name="rois", shape=[20, 5], dtype="float32") | ||
| output, argmaxes = layers.roi_pool(x, rois, 7, 7, 0.6) | ||
| self.assertIsNotNone(output) | ||
| self.assertIsNotNone(argmaxes) | ||
| print(str(program)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add
roi_poolin doc : https://github.com/PaddlePaddle/Paddle/blob/develop/doc/fluid/api/layers.rst#nn