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


Python attr.gpu方法代码示例

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


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

示例1: _test_call

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def _test_call(self, gpu):
        nonlinearity = getattr(F, self.nonlinearity)
        mlp = chainerrl.links.MLPBN(
            in_size=self.in_size,
            out_size=self.out_size,
            hidden_sizes=self.hidden_sizes,
            normalize_input=self.normalize_input,
            normalize_output=self.normalize_output,
            nonlinearity=nonlinearity,
            last_wscale=self.last_wscale,
        )
        batch_size = 7
        x = np.random.rand(batch_size, self.in_size).astype(np.float32)
        if gpu >= 0:
            mlp.to_gpu(gpu)
            x = chainer.cuda.to_gpu(x)
        y = mlp(x)
        self.assertEqual(y.shape, (batch_size, self.out_size))
        self.assertEqual(chainer.cuda.get_array_module(y),
                         chainer.cuda.get_array_module(x)) 
开发者ID:chainer,项目名称:chainerrl,代码行数:22,代码来源:test_mlp_bn.py

示例2: test_forward_cpu_gpu_equal

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def test_forward_cpu_gpu_equal(self):
        # cpu
        x_cpu = chainer.Variable(self.x)
        rois_cpu = chainer.Variable(self.rois)
        roi_indices_cpu = chainer.Variable(self.roi_indices)
        y_cpu = functions.roi_average_pooling_2d(
            x_cpu, rois_cpu, roi_indices_cpu, outsize=self.outsize,
            spatial_scale=self.spatial_scale)

        # gpu
        x_gpu = chainer.Variable(cuda.to_gpu(self.x))
        rois_gpu = chainer.Variable(cuda.to_gpu(self.rois))
        roi_indices_gpu = chainer.Variable(cuda.to_gpu(self.roi_indices))
        y_gpu = functions.roi_average_pooling_2d(
            x_gpu, rois_gpu, roi_indices_gpu, outsize=self.outsize,
            spatial_scale=self.spatial_scale)
        testing.assert_allclose(y_cpu.data, cuda.to_cpu(y_gpu.data)) 
开发者ID:chainer,项目名称:chainer,代码行数:19,代码来源:test_roi_average_pooling_2d.py

示例3: test_forward_cpu_gpu_equal

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def test_forward_cpu_gpu_equal(self):
        # cpu
        x_cpu = chainer.Variable(self.x)
        rois_cpu = chainer.Variable(self.rois)
        roi_indices_cpu = chainer.Variable(self.roi_indices)
        y_cpu = functions.roi_max_pooling_2d(
            x_cpu, rois_cpu, roi_indices_cpu, outsize=self.outsize,
            spatial_scale=self.spatial_scale)

        # gpu
        x_gpu = chainer.Variable(cuda.to_gpu(self.x))
        rois_gpu = chainer.Variable(cuda.to_gpu(self.rois))
        roi_indices_gpu = chainer.Variable(cuda.to_gpu(self.roi_indices))
        y_gpu = functions.roi_max_pooling_2d(
            x_gpu, rois_gpu, roi_indices_gpu, outsize=self.outsize,
            spatial_scale=self.spatial_scale)
        testing.assert_allclose(y_cpu.data, cuda.to_cpu(y_gpu.data)) 
开发者ID:chainer,项目名称:chainer,代码行数:19,代码来源:test_roi_max_pooling_2d.py

示例4: test_forward_cpu_gpu_equal

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def test_forward_cpu_gpu_equal(self):
        # cpu
        x_cpu = chainer.Variable(self.x)
        rois_cpu = chainer.Variable(self.rois)
        roi_indices_cpu = chainer.Variable(self.roi_indices)
        y_cpu = functions.roi_average_align_2d(
            x_cpu, rois_cpu, roi_indices_cpu, outsize=self.outsize,
            spatial_scale=self.spatial_scale,
            sampling_ratio=self.sampling_ratio,
        )

        # gpu
        x_gpu = chainer.Variable(cuda.to_gpu(self.x))
        rois_gpu = chainer.Variable(cuda.to_gpu(self.rois))
        roi_indices_gpu = chainer.Variable(cuda.to_gpu(self.roi_indices))
        y_gpu = functions.roi_average_align_2d(
            x_gpu, rois_gpu, roi_indices_gpu, outsize=self.outsize,
            spatial_scale=self.spatial_scale,
            sampling_ratio=self.sampling_ratio,
        )
        testing.assert_allclose(y_cpu.data, cuda.to_cpu(y_gpu.data)) 
开发者ID:chainer,项目名称:chainer,代码行数:23,代码来源:test_roi_average_align_2d.py

示例5: get_pytest_marks

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def get_pytest_marks(self):
        marks = []
        if self.use_chainerx:
            marks.append(attr.chainerx)
            backend_name, device_index = self.chainerx_device.split(':')
            device_index = int(device_index)
            if backend_name == 'cuda':
                marks.append(attr.gpu)
                if device_index >= 1:
                    marks.append(attr.multi_gpu(device_index + 1))
        elif self.use_cuda:
            marks.append(attr.gpu)
            if self.use_cudnn != 'never':
                marks.append(attr.cudnn)
            if self.cuda_device >= 1:
                marks.append(attr.multi_gpu(self.cuda_device + 1))
        else:
            if self.use_ideep != 'never':
                marks.append(attr.ideep)

        assert all(callable(_) for _ in marks)
        return marks 
开发者ID:chainer,项目名称:chainer,代码行数:24,代码来源:backend.py

示例6: test_forward_cpu_gpu_equal

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [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_align_2d(
            x_cpu, rois_cpu, outh=self.outh, outw=self.outw,
            spatial_scale=self.spatial_scale,
            sampling_ratio=self.sampling_ratio,
        )

        # gpu
        x_gpu = chainer.Variable(cuda.to_gpu(self.x))
        rois_gpu = chainer.Variable(cuda.to_gpu(self.rois))
        y_gpu = functions.roi_align_2d(
            x_gpu, rois_gpu, outh=self.outh, outw=self.outw,
            spatial_scale=self.spatial_scale,
            sampling_ratio=self.sampling_ratio,
        )
        testing.assert_allclose(y_cpu.data, cuda.to_cpu(y_gpu.data)) 
开发者ID:wkentaro,项目名称:chainer-mask-rcnn,代码行数:21,代码来源:test_roi_align_2d.py

示例7: _test_call

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def _test_call(self, gpu):
        nonlinearity = getattr(F, self.nonlinearity)
        model = chainerrl.q_functions.FCSAQFunction(
            n_dim_obs=self.n_dim_obs,
            n_dim_action=self.n_dim_action,
            n_hidden_layers=self.n_hidden_layers,
            n_hidden_channels=self.n_hidden_channels,
            nonlinearity=nonlinearity,
            last_wscale=self.last_wscale,
        )
        self._test_call_given_model(model, gpu) 
开发者ID:chainer,项目名称:chainerrl,代码行数:13,代码来源:test_state_action_q_function.py

示例8: test_call_cpu

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def test_call_cpu(self):
        self._test_call(gpu=-1) 
开发者ID:chainer,项目名称:chainerrl,代码行数:4,代码来源:test_state_action_q_function.py

示例9: test_call_gpu

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def test_call_gpu(self):
        self._test_call(gpu=0) 
开发者ID:chainer,项目名称:chainerrl,代码行数:4,代码来源:test_state_action_q_function.py

示例10: _test_call

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def _test_call(self, gpu):
        # This method only check if a given model can receive random input
        # data and return output data with the correct interface.
        nonlinearity = getattr(F, self.nonlinearity)
        min_action = np.full((self.action_size,), -0.01, dtype=np.float32)
        max_action = np.full((self.action_size,), 0.01, dtype=np.float32)
        model = self._make_model(
            n_input_channels=self.n_input_channels,
            action_size=self.action_size,
            bound_action=self.bound_action,
            min_action=min_action,
            max_action=max_action,
            nonlinearity=nonlinearity,
        )

        batch_size = 7
        x = np.random.rand(
            batch_size, self.n_input_channels).astype(np.float32)
        if gpu >= 0:
            model.to_gpu(gpu)
            x = chainer.cuda.to_gpu(x)
            min_action = chainer.cuda.to_gpu(min_action)
            max_action = chainer.cuda.to_gpu(max_action)
        y = model(x)
        self.assertTrue(isinstance(
            y, chainerrl.distribution.ContinuousDeterministicDistribution))
        a = y.sample()
        self.assertTrue(isinstance(a, chainer.Variable))
        self.assertEqual(a.shape, (batch_size, self.action_size))
        self.assertEqual(chainer.cuda.get_array_module(a),
                         chainer.cuda.get_array_module(x))
        if self.bound_action:
            self.assertTrue((a.array <= max_action).all())
            self.assertTrue((a.array >= min_action).all()) 
开发者ID:chainer,项目名称:chainerrl,代码行数:36,代码来源:test_deterministic_policy.py

示例11: _get_method

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def _get_method(self, prefix, gpu):
        suffix = 'gpu' if gpu else 'cpu'
        return getattr(self.f, prefix + '_' + suffix) 
开发者ID:chainer,项目名称:chainer,代码行数:5,代码来源:test_function_node.py

示例12: check_forward

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def check_forward(self, gpu):
        y1, y2 = self.f.forward((self.x1, self.x2))
        self.assertEqual(self.f.check_type_forward.call_count, 0)
        self.assertEqual(self._get_method('forward', not gpu).call_count, 0)
        self._get_method('forward', gpu).assert_called_once_with(
            (self.x1, self.x2))
        self.assertTrue((cuda.to_cpu(y1) == cuda.to_cpu(self.y1)).all())
        self.assertTrue((cuda.to_cpu(y2) == cuda.to_cpu(self.y2)).all()) 
开发者ID:chainer,项目名称:chainer,代码行数:10,代码来源:test_function_node.py

示例13: check_backward

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def check_backward(self, gpu):
        gx1, gx2 = self.f.backward((self.x1, self.x2), (self.gy1, self.gy2))
        self.assertEqual(self._get_method('backward', not gpu).call_count, 0)
        self._get_method('backward', gpu).assert_called_once_with(
            (self.x1, self.x2), (self.gy1, self.gy2))
        self.assertTrue((cuda.to_cpu(gx1) == cuda.to_cpu(self.gx1)).all())
        self.assertIsNone(gx2) 
开发者ID:chainer,项目名称:chainer,代码行数:9,代码来源:test_function.py

示例14: test_forward_mixed_cpu_gpu_1

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def test_forward_mixed_cpu_gpu_1(self):
        # self.link is not sent to gpu
        with self.assertRaises(TypeError):
            self.check_forward(cuda.to_gpu(self.x)) 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_embed_id.py

示例15: test_forward_mixed_cpu_gpu_2

# 需要导入模块: from chainer.testing import attr [as 别名]
# 或者: from chainer.testing.attr import gpu [as 别名]
def test_forward_mixed_cpu_gpu_2(self):
        with testing.assert_warns(DeprecationWarning):
            self.link.to_gpu()
        with self.assertRaises(TypeError):
            # self.x is not sent to gpu
            self.check_forward(self.x) 
开发者ID:chainer,项目名称:chainer,代码行数:8,代码来源:test_embed_id.py


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