在python脚本最开头已经
import torch
但在后面用到的时候:
if not torch.cuda.is_available():
print('using CPU')
却报错了:
UnboundLocalError: local variable 'torch' referenced before assignment
在后面调用的语句之前也没有对torch这个词赋过别的值。
真的非常奇怪,不知道怎么会这样,有没有大佬遇到过这样的问题呢?