This error occurred in Python.
At first, the reason is that I want to change the list with a tensor to a tensor type, that is, [tensor (), tensor ()] to a tensor, and then I write like this,
a = torch.randn(1,2) # tensor([[-0.4962, 0.6034]]) d = [a, a, a] # [tensor([[-0.4962, 0.6034]]), tensor([[-0.4962, 0.6034]]), tensor([[-0.4962, 0.6034]])] d = torch.tensor(d)
It’s a mistake. ValueError: only one element tensors can be converted to Python scalars
I see a solution on the Internet,
val= torch.tensor([item.cpu().detach().numpy() for item in val]).cuda()
This method is very unsophisticated and concise.
Another way is to use torch. Cat, which is very concise. If you want to expand dimensions, you can use operations such as unsqueeze on this basis.
d = torch.cat(d, 0) ''' Output: tensor([[-0.4962, 0.6034], [-0.4962, 0.6034], [-0.4962, 0.6034]]) '''
- torch.nn.functional.normalize() Function Interpretation
- Here is the difference and connection of Torch. View (), Transpose (), and Permute ()
- Python: Torch.nn.functional.normalize() Function
- Python: RNN principle realized by numpy
- [Solved] PyTorch Caught RuntimeError in DataLoader worker process 0和invalid argument 0: Sizes of tensors mus
- Autograd error in Python: runtimeerror: grad can be implicitly created only for scalar outputs
- The lenet model trained by Python failed to predict its own handwritten pictures
- [Solved] Pytorch Tensor to numpy error: RuntimeError: Can‘t call numpy() on Tensor that requires grad.报错
- Pytorch: How to Handle error warning conda.gateways.disk.delete:unlink_or_rename_to_trash(140)
- How to Solve RuntimeError: cuDNN error: CUDNN_STATUS_EXECUTION_FAILED
- pytorch: RuntimeError CUDA error device-side assert triggered
- [Solved] RuntimeError: cublas runtime error : resource allocation failed at
- [Solved] RuntimeError : PyTorch was compiled without NumPy support
- Pytorch ValueError: Expected more than 1 value per channel when training, got input size [1, 768
- Python RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 1, 5, 5]
- Python custom convolution kernel weight parameters
- [Solved] Pytorch-geometric Error: No module named torch_sparse
- [Solved] Tensorflow cuda Error: Could not load dynamic library ‘libcudart.so.11.0‘； dlerror: libcudart.so.11.0:
- [Exception]’ascii’ codec can’t decode byte 0xe8 in position 2: ordinal not in range(128)
- [CHM] Python: How to Extract CHM Data