标题说明了一切.我想将a转换PyTorch autograd.Variable为其等效numpy数组.在他们的官方文档中,他们主张使用a.numpy()获取等效numpy数组(for PyTorch tensor).但这给了我以下错误:
回溯(最近一次调用最后一次):文件"stdin",第1行,在模块文件"/home/bishwajit/anaconda3/lib/python3.6/site-packages/torch/autograd/variable.py",第63行,getattr raise AttributeError(name)AttributeError:numpy
有什么办法可以绕过这个吗?
First of all, I tried those solutions: 1, 2, 3, and 4, but did not work for me.
After training and testing the neural network, I am trying to show some examples to verify my work. I named the method predict which I pass the image to it to predict for which class it belongs:
def predict(model, image_path, topk=5):
''' Predict the class (or classes) of an image using a trained deep learning model.
'''
output …Run Code Online (Sandbox Code Playgroud)