Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
rename psroi_pooling_2d -> ps_roi_average_pooling_2d
Browse files Browse the repository at this point in the history
  • Loading branch information
knorth55 committed Feb 18, 2019
1 parent a865c56 commit 4fadead
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions chainercv/experimental/links/model/fcis/fcis_resnet101.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np

from chainercv.experimental.links.model.fcis import FCIS
from chainercv.functions import psroi_pooling_2d
from chainercv.functions import ps_roi_average_pooling_2d
from chainercv.links import Conv2DBNActiv
from chainercv.links.model.faster_rcnn.region_proposal_network import \
RegionProposalNetwork
Expand Down Expand Up @@ -365,7 +365,7 @@ def _pool(
self, h_cls_seg, h_ag_loc, rois, roi_indices, gt_roi_labels):
# PSROI Pooling
# shape: (n_roi, n_class, 2, roi_size, roi_size)
roi_cls_ag_seg_scores = psroi_pooling_2d(
roi_cls_ag_seg_scores = ps_roi_average_pooling_2d(
h_cls_seg, rois, roi_indices,
self.n_class * 2, self.roi_size, self.roi_size,
self.spatial_scale, self.group_size)
Expand All @@ -374,7 +374,7 @@ def _pool(
(-1, self.n_class, 2, self.roi_size, self.roi_size))

# shape: (n_roi, 2*4, roi_size, roi_size)
roi_ag_loc_scores = psroi_pooling_2d(
roi_ag_loc_scores = ps_roi_average_pooling_2d(
h_ag_loc, rois, roi_indices,
2 * 4, self.roi_size, self.roi_size,
self.spatial_scale, self.group_size)
Expand Down
3 changes: 1 addition & 2 deletions chainercv/functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from chainercv.functions.psroi_pooling_2d import psroi_pooling_2d # NOQA
from chainercv.functions.psroi_pooling_2d import PSROIPooling2D # NOQA
from chainercv.functions.ps_roi_average_pooling_2d import ps_roi_average_pooling_2d # NOQA
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _roi_pooling_slice(size, stride, max_size, roi_offset):
return slice(start, end), end - start


class PSROIPooling2D(function.Function):
class PSROIAveragePooling2D(function.Function):

def __init__(self, out_c, out_h, out_w, spatial_scale, group_size):
self.out_c, self.out_h, self.out_w = out_c, out_h, out_w
Expand Down Expand Up @@ -197,7 +197,7 @@ def forward_gpu(self, inputs):
float bin_area = (hend - hstart) * (wend - wstart);
top_data = is_empty? (float) 0. : out_sum / bin_area;
''', 'psroi_pooling_2d_fwd'
''', 'ps_roi_average_pooling_2d_fwd'
)(bottom_data, bottom_rois, bottom_roi_indices,
self.spatial_scale, channels, height, width,
self.out_c, self.out_h, self.out_w, self.group_size,
Expand Down Expand Up @@ -327,7 +327,7 @@ def backward_gpu(self, inputs, gy):
&bottom_diff[bottom_diff_offset + bottom_index], diff_val);
}
}
''', 'psroi_pooling_2d_bwd'
''', 'ps_roi_average_pooling_2d_bwd'
)(gy[0], bottom_rois, bottom_roi_indices,
self.spatial_scale, channels, height, width,
self.out_c, self.out_h, self.out_w,
Expand All @@ -336,11 +336,11 @@ def backward_gpu(self, inputs, gy):
return bottom_diff, None, None


def psroi_pooling_2d(
def ps_roi_average_pooling_2d(
x, rois, roi_indices, out_c, out_h, out_w,
spatial_scale, group_size
):
"""Position Sensitive Region of Interest (ROI) pooling function.
"""Position Sensitive Region of Interest (ROI) Average pooling function.
This function computes position sensitive average of input spatial patch
with the given region of interests. Each ROI is splitted into
Expand Down Expand Up @@ -368,5 +368,5 @@ def psroi_pooling_2d(
`R-FCN <https://arxiv.org/abs/1605.06409>`_.
"""
return PSROIPooling2D(out_c, out_h, out_w, spatial_scale,
group_size)(x, rois, roi_indices)
return PSROIAveragePooling2D(out_c, out_h, out_w, spatial_scale,
group_size)(x, rois, roi_indices)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from chainercv import functions


class TestPSROIPolling2D(unittest.TestCase):
class TestPSROIAveragePolling2D(unittest.TestCase):

def setUp(self):
self.N = 3
Expand Down Expand Up @@ -43,7 +43,7 @@ def check_forward(self, x_data, roi_data, roi_index_data):
x = chainer.Variable(x_data)
rois = chainer.Variable(roi_data)
roi_indices = chainer.Variable(roi_index_data)
y = functions.psroi_pooling_2d(
y = functions.ps_roi_average_pooling_2d(
x, rois, roi_indices, self.out_c, self.out_h, self.out_w,
self.spatial_scale, self.group_size)
self.assertEqual(y.data.dtype, np.float32)
Expand All @@ -63,11 +63,12 @@ def test_forward_gpu(self):
cuda.to_gpu(self.roi_indices))

def check_backward(self, x_data, roi_data, roi_index_data, y_grad_data):
def f(x, rois, roi_indices):
return functions.ps_roi_average_pooling_2d(
x, rois, roi_indices, self.out_c, self.out_h, self.out_w,
self.spatial_scale, self.group_size)
gradient_check.check_backward(
functions.PSROIPooling2D(
self.out_c, self.out_h, self.out_w,
self.spatial_scale, self.group_size),
(x_data, roi_data, roi_index_data), y_grad_data,
f, (x_data, roi_data, roi_index_data), y_grad_data,
no_grads=[False, True, True], **self.check_backward_options)

@condition.retry(3)
Expand All @@ -85,7 +86,7 @@ def apply_backward(self, x_data, roi_data, roi_index_data, y_grad_data):
x = chainer.Variable(x_data)
rois = chainer.Variable(roi_data)
roi_indices = chainer.Variable(roi_index_data)
y = functions.psroi_pooling_2d(
y = functions.ps_roi_average_pooling_2d(
x, rois, roi_indices, self.out_c, self.out_h, self.out_w,
self.spatial_scale, self.group_size)
x.cleargrad()
Expand Down

0 comments on commit 4fadead

Please sign in to comment.