admin管理员组

文章数量:1608852

在使用torchvision的op的时候,比如from torchvision.ops.nms如果遇到以下的问题:

Couldn’t load custom C++ ops. This can happen if your PyTorch and
torchvision versions are incompatible, or if you had errors while compiling
torchvision from source. For further information on the compatible versions, check
https://github/pytorch/vision#installation for the compatibility matrix.
Please check your PyTorch version with torch.version and your torchvision
version with torchvision.version and verify if they are compatible, and if not
please reinstall torchvision so that it matches your PyTorch install.

发现进入torchvision中在这里打印出来:

def _assert_has_ops():
    if not _has_ops():
        raise RuntimeError(
            "Couldn't load custom C++ ops. This can happen if your PyTorch and "
            "torchvision versions are incompatible, or if you had errors while compiling "
            "torchvision from source. For further information on the compatible versions, check "
            "https://github/pytorch/vision#installation for the compatibility matrix. "
            "Please check your PyTorch version with torch.__version__ and your torchvision "
            "version with torchvision.__version__ and verify if they are compatible, and if not "
            "please reinstall torchvision so that it matches your PyTorch install."
        )

原因就是pytorch版本和torchvision没有匹配,必须要完全匹配。

通过pip list命令查看的时候是这样的才行:

torch                   1.8.1+cu111
torchvision             0.9.1+cu111

比如1.8.1对应0.9.1,而1.8.0对应0.9.1,这个匹配关系可以看官方的。而且后面的cu111必须也一致!
不一致的话,直接输入网址安装就行:

 pip install https://download.pytorch/whl/cu111/torchvision-0.9.1%2Bcu111-cp38-cp38-linux_x86_64.whl

官方的地址:
https://download.pytorch/whl/

本文标签: TorchVisionop