当前位置: 首页>>代码示例>>Python>>正文


Python functions.roi_pooling_2d方法代码示例

本文整理汇总了Python中chainer.functions.roi_pooling_2d方法的典型用法代码示例。如果您正苦于以下问题:Python functions.roi_pooling_2d方法的具体用法?Python functions.roi_pooling_2d怎么用?Python functions.roi_pooling_2d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainer.functions的用法示例。


在下文中一共展示了functions.roi_pooling_2d方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import roi_pooling_2d [as 别名]
def check_forward(self, x_data, roi_data):
        x = chainer.Variable(x_data)
        rois = chainer.Variable(roi_data)
        y = functions.roi_pooling_2d(
            x, rois, outh=self.outh, outw=self.outw,
            spatial_scale=self.spatial_scale)
        self.assertEqual(y.data.dtype, self.dtype)
        y_data = cuda.to_cpu(y.data)

        self.assertEqual(self.gy.shape, y_data.shape) 
开发者ID:chainer,项目名称:chainer,代码行数:12,代码来源:test_roi_pooling_2d.py

示例2: test_forward_cpu_gpu_equal

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import roi_pooling_2d [as 别名]
def test_forward_cpu_gpu_equal(self):
        # cpu
        x_cpu = chainer.Variable(self.x)
        rois_cpu = chainer.Variable(self.rois)
        y_cpu = functions.roi_pooling_2d(
            x_cpu, rois_cpu, outh=self.outh, outw=self.outw,
            spatial_scale=self.spatial_scale)

        # gpu
        x_gpu = chainer.Variable(cuda.to_gpu(self.x))
        rois_gpu = chainer.Variable(cuda.to_gpu(self.rois))
        y_gpu = functions.roi_pooling_2d(
            x_gpu, rois_gpu, outh=self.outh, outw=self.outw,
            spatial_scale=self.spatial_scale)
        testing.assert_allclose(y_cpu.data, cuda.to_cpu(y_gpu.data)) 
开发者ID:chainer,项目名称:chainer,代码行数:17,代码来源:test_roi_pooling_2d.py

示例3: check_backward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import roi_pooling_2d [as 别名]
def check_backward(self, x_data, roi_data, y_grad):
        def f(x, rois):
            return functions.roi_pooling_2d(
                x, rois, outh=self.outh, outw=self.outw,
                spatial_scale=self.spatial_scale)

        gradient_check.check_backward(
            f, (x_data, roi_data), y_grad, no_grads=[False, True],
            **self.check_backward_options) 
开发者ID:chainer,项目名称:chainer,代码行数:11,代码来源:test_roi_pooling_2d.py

示例4: setUp

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import roi_pooling_2d [as 别名]
def setUp(self):
        # these parameters are referenced from chainer test
        in_shape = (3, 3, 12, 8)
        self.x = input_generator.positive_increasing(*in_shape)
        # In chainer test, x is shuffled and normalize-like conversion,
        # In this test, those operations are skipped.
        # If x includes negative value, not match with onnxruntime output.
        # You can reproduce this issue by changing `positive_increasing` to
        # `increase`
        self.rois = np.array([
            [0, 1, 1, 6, 6],
            [2, 6, 2, 7, 11],
            [1, 3, 1, 5, 10],
            [0, 3, 3, 3, 3]], dtype=np.float32)
        kwargs = {
            'outh': 3,
            'outw': 7,
            'spatial_scale': 0.6
        }

        class Model(chainer.Chain):
            def __init__(self, kwargs):
                super(Model, self).__init__()
                self.kwargs = kwargs

            def __call__(self, x, rois):
                return F.roi_pooling_2d(x, rois, **self.kwargs)

        self.model = Model(kwargs) 
开发者ID:chainer,项目名称:chainer,代码行数:31,代码来源:test_poolings.py

示例5: test_roi_module

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import roi_pooling_2d [as 别名]
def test_roi_module():
    ## fake data###
    B, N, C, H, W, PH, PW = 2, 8, 4, 32, 32, 7, 7

    bottom_data = t.randn(B, C, H, W).cuda()
    bottom_rois = t.randn(N, 5)
    bottom_rois[:int(N / 2), 0] = 0
    bottom_rois[int(N / 2):, 0] = 1
    bottom_rois[:, 1:] = (t.rand(N, 4) * 100).float()
    bottom_rois = bottom_rois.cuda()
    spatial_scale = 1. / 16
    outh, outw = PH, PW

    # pytorch version
    module = RoIPooling2D(outh, outw, spatial_scale)
    x = bottom_data.requires_grad_()
    rois = bottom_rois.detach()

    output = module(x, rois)
    output.sum().backward()

    def t2c(variable):
        npa = variable.data.cpu().numpy()
        return cp.array(npa)

    def test_eq(variable, array, info):
        cc = cp.asnumpy(array)
        neq = (cc != variable.data.cpu().numpy())
        assert neq.sum() == 0, 'test failed: %s' % info

    # chainer version,if you're going to run this
    # pip install chainer 
    import chainer.functions as F
    from chainer import Variable
    x_cn = Variable(t2c(x))

    o_cn = F.roi_pooling_2d(x_cn, t2c(rois), outh, outw, spatial_scale)
    test_eq(output, o_cn.array, 'forward')
    F.sum(o_cn).backward()
    test_eq(x.grad, x_cn.grad, 'backward')
    print('test pass') 
开发者ID:FederatedAI,项目名称:FATE,代码行数:43,代码来源:roi_module.py

示例6: _roi_pooling_2d_yx

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import roi_pooling_2d [as 别名]
def _roi_pooling_2d_yx(x, indices_and_rois, outh, outw, spatial_scale):
    xy_indices_and_rois = indices_and_rois[:, [0, 2, 1, 4, 3]]
    pool = F.roi_pooling_2d(
        x, xy_indices_and_rois, outh, outw, spatial_scale)
    return pool 
开发者ID:chainer,项目名称:chainercv,代码行数:7,代码来源:faster_rcnn_vgg.py


注:本文中的chainer.functions.roi_pooling_2d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。