當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。