相关疑难解决方法(0)

如何将Pytorch autograd.Variable转换为Numpy?

标题说明了一切.我想将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

有什么办法可以绕过这个吗?

numpy pytorch tensor

15
推荐指数
2
解决办法
1万
查看次数

Convert CUDA tensor to 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)

python numpy pytorch

3
推荐指数
1
解决办法
6394
查看次数

标签 统计

numpy ×2

pytorch ×2

python ×1

tensor ×1