在torch的主頁上有這樣一句話,經過仔細分析才明白其中的意思:
Pylint isn't picking up that torch
has
the member function from_numpy
. It's
because torch.from_numpy
is actually torch._C.from_numpy
as
far as Pylint is concerned.
本身而言,pytorch並不直接包含from_numpy這個方法,而需要通過_C這樣的命名空間來調用。
因此解決方案:
1.用torch._C.from_numpy
因此利用._C的辦法進行測試,果然順利通過。
2.sudo pip install pylint 或 sudo pip3 install pylint (根據python版本決定)
再用torch.from_numpy就不會報錯