RuntimeError: Integer division of tensors using div or/is no longer supported, and in a future release div will perform true division as in Python 3. Use true_divide or floor_divide (// in Python) instead.
from torchvision import transforms
import numpy as np
data = np.random.randint(0, 255, size=12)
img = data.reshape(2, 2, 3)
print(img.shape)
img_tensor = transforms.ToTensor()(img) # Convert to tensor
print(img_tensor)
print(img_tensor.shape)
print("*" * 20)
norm_img = transforms.Normalize((10, 10, 10), (1, 1, 1))(img_tensor) # Perform normative processing
print(norm_img)
Operation effect:
reason:
Pytorch1.5.0 is OK, but when upgrading to 1.6.0, it is found that division between tenor and int cannot be directly performed with ‘/’.
Solution:
Standardize the data processing
Example code:
from torchvision import transforms
import numpy as np
data = np.random.randint(0, 255, size=12)
img = data.reshape(2, 2, 3)
print(img.shape)
img_tensor = transforms.ToTensor()(img) # convert to tensor
print(img_tensor)
print(img_tensor.shape)
print("*" * 20)
img_tensor = img_tensor.float() # Add this line
norm_img = transforms.Normalize((10, 10, 10), (1, 1, 1))(img_tensor) # Perform normalization
print(norm_img)
Results of operation:
Read More:
- Xcode debugging for the real iPhone Error: code signature version is no longer supported
- [Solved] RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of s
- [Solved] pytorch CrossEntropyLoss Error: RuntimeError: 1D target tensor expected, multi-target not supported
- Error in Tensorflow using variables: List of Tensors when single Tensor expected
- RuntimeError: Exporting the operator uniform to ONNX opset version 12 is not supported.
- How to Solve Error: RuntimeError: all tensors must be on devices[0]
- ORA-08103: object no longer exists [How to Solve]
- [Solved] VINS-MONO: integer_sequence_algorithm.h:64:21: error: ‘integer_sequence’ is not a member of ‘std’
- [Solved] RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and
- [Solved] Springboot WARNING: All illegal access operations will be denied in a future release
- [Solved] bin/hive Startup Error: Operation category READ is not supported in state standby
- [Solved] RuntimeError: each element in list of batch should be of equal size
- Error: array bound is not an integer constant before ‘]’ token
- [Solved] MSYS2+ fatal error: zlib.h: There is no such file or directory
- [Solved] ROS fatal error: alsa/asoundlib. h: There is no such directory or file
- [Solved] A-LOAM Ceres Compile Error: error: ‘integer_sequence’ is not a member of ‘std‘
- React Hook “useState“ is called in function “xxx“ which is neither a React function component or
- [Solved] TortoiseGitPlink Fatal Error: No supported authentication methods available (server sent: publi
- [Solved] Websocket Error: WebSocket is already in CLOSING or CLOSED state
- How to Solve Pandas Error: nested renamer is not supported python