The following error is reported when using tensor ` normalization
from torchvision import transforms
import numpy as np
import torchvision
import torch
data = np.random.randint(0, 255, size=12)
img = data.reshape(2,2,3)
print(img)
print("*"*100)
transform1 = transforms.Compose([
transforms.ToTensor(), # range [0, 255] -> [0.0,1.0]
transforms.Normalize(mean = (10,10,10), std = (1,1,1)),
]
)
# img = img.astype('float')
norm_img = transform1(img)
print(norm_img)
You can add this sentence. In fact, it is to set the element type. See the tips above
Read More:
- [Solved] Pytorch Tensor to numpy error: RuntimeError: Can‘t call numpy() on Tensor that requires grad.报错
- [Solved] RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dim
- RuntimeError: stack expects each tensor to be equal size [How to Solve]
- Tensor for argument #2 ‘mat1‘ is on CPU, but expected it to be on GPU (while checking arguments for
- RuntimeError: stack expects each tensor to be equal size, but got [x] at entry 0 and [x] at entry 1
- Pytorch directly creates a tensor on the GPU error [How to Solve]
- RuntimeError: Failed to register operator torchvision::_new_empty_tensor_op. +torch&torchversion Version Matching
- [Solved] Pytorch Error: AttributeError: ‘Tensor‘ object has no attribute ‘backword‘
- [Solved] pytorch Error: KeyError: tensor(2, device=‘cuda:0‘)
- Python: Torch.nn.functional.normalize() Function
- torch.nn.functional.normalize() Function Interpretation
- [Solved] Operator Not Allowed In Graph Error & Attribute Error Tensor object has no attribute numpy
- [How to Fix] TypeError: Cannot cast array data from dtype(‘float64‘) to dtype(‘<U32‘)….
- Pytorch Error: RuntimeError: value cannot be converted to type float without overflow: (0.00655336,-0.00
- [Solved] Pytorch Error: RuntimeError: expected scalar type Double but found Float
- [Solved] RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- [Solved] Runtime error: expected scalar type Float but found Double
- [Solved] Matplotlib scatter Draw Error: TypeError: ufunc ‘sqrt‘ not supported for the input types…rule ‘‘safe‘‘
- [Solved] ValueError: Error when checking input: expected conv2d_input to have 4 dimensions