cuda runtime error (801) : operation not supported

今天做了一个界面,想到模型预测占据大量的运算,会对界面造成影响,很可能会造成界面卡死。所以另外新开一个进程去预测图片,又考虑到如果在子进程中加载模型,那么每次预测图片都需要进行加载模型这个过程,太浪费时间,于是考虑在主进程中开一个线程加载模型,然后通过管道来讲模型传递到子进程中,然后,代码运行起来后,报错了 ,如下:

cuda runtime error (801) : operation not supported at C:\w\b\windows\pytorch\torch/csrc/generic/StorageSharing.cpp:245
THCudaCheck FAIL file=C:\w\b\windows\pytorch\torch/csrc/generic/StorageSharing.cpp line=245 error=801 : operation not supported

这个问题第一次遇见,最后找到解决方法,如下:
首先,在主进程中,我加载模型的时候代码如下:

net = models.resnet().to(device)

大家不用关注这里究竟加载了什么模型,只需要知道我在主进程中就把模型放到gpu上了,这也是报错的原因所在,因此,我将代码改成下面这种:

net = models.resnet()

然后我再在子进程中将模型放到gpu上,ok,正常运行了。

2020.10.21

你可能感兴趣的:(pytorch,cv)