PyTorch 'Tensor' object has no attribute 'numpy': How to Convert to NumPy Array
This error occurs when trying to call the '.numpy()' method on a PyTorch tensor object. This method is only available on NumPy arrays, not on PyTorch tensors.
To fix this error, you can convert the PyTorch tensor object to a NumPy array using the '.detach().numpy()' method, like this:
inputs_np = inputs.detach().numpy()
This will create a NumPy array from the PyTorch tensor, which can then be used with NumPy functions and methods.
原文地址: https://www.cveoy.top/t/topic/jr6Y 著作权归作者所有。请勿转载和采集!