Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于GPU的链式预测_Python_Deep Learning_Gpu_Chainer - Fatal编程技术网

Python 基于GPU的链式预测

Python 基于GPU的链式预测,python,deep-learning,gpu,chainer,Python,Deep Learning,Gpu,Chainer,我有一个训练有素的链式模型,我想用它来进行预测。默认情况下,我可以在CPU上预测图像,但我想使用GPU,但我不确定该怎么做。 下面是我的代码的样子: model = MyModel() chainer.serializers.load_npz("snapshot", model) image = load_image(path) # returns a numpy array with chainer.no_brackprop_mode(), chainer.using_config("tra

我有一个训练有素的链式模型,我想用它来进行预测。默认情况下,我可以在CPU上预测图像,但我想使用GPU,但我不确定该怎么做。 下面是我的代码的样子:

model = MyModel()
chainer.serializers.load_npz("snapshot", model)
image = load_image(path) # returns a numpy array

with chainer.no_brackprop_mode(), chainer.using_config("train", False):
    pred = model.__call__(image)
这在CPU上运行良好。我应该添加什么来预测GPU? 我试过:

  • model.to\u gpu(0)
  • chainer.cuda.get\u device\u from\u id(0)。use()
  • 使用
    image=CuPy.array(image)
使用所有这些选项,我会得到一个错误:

ValueError: numpy and cupy must not be used together
type(W): <type 'cupy.core.core.ndarray'>, type(x): <type 'numpy.ndarray'>
ValueError:numpy和cupy不能一起使用
类型(W):,类型(x):
我做错了什么?如何在GPU上执行预测?
提前感谢您的帮助。

我终于想出了一个让它工作的方法: 我没有使用
cupy.array(image)
,而是使用
cuda.to\u gpu(image)
,然后使用
cuda.to\u cpu(image)
。我不确定这两者之间的区别,但仍然有效