错误描述:
Traceback (most recent call last):
File "C:/Users/Administrator/Desktop/PubLayNet-maskrcnn/PubLayNet/maskrcnn/infer.py", line 117, in <module>
main()
File "C:/Users/Administrator/Desktop/PubLayNet-maskrcnn/PubLayNet/maskrcnn/infer.py", line 91, in main
prediction = model([image.cuda()])
File "E:\Anaconda3\lib\site-packages\torch\cuda\__init__.py", line 178, in _lazy_init
_check_driver()
File "E:\Anaconda3\lib\site-packages\torch\cuda\__init__.py", line 92, in _check_driver
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
此错误是由于下载的torch没有cuda,在运行时就会出错,经过查阅,在程序最开始的地方加上:
device = torch.device(“cuda” if torch.cuda.is_available() else “cpu”)
代码其余地方出现.cuda()的地方改成.to(device)就可以在无gpu的环境中运行了。
# model.cuda()
model.to(device)
# prediction = model([image.cuda()])
prediction = model([image.to(device)])