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)
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 ‘/’.
Standardize the data processing
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:
- Error in Tensorflow using variables: List of Tensors when single Tensor expected
- TypeError: unsupported format string passed to numpy.ndarray.__format__
- ValueError: Floating point image RGB values must be in the 0..1 range.
- AUC Error – ValueError: Data is not binary and pos_label is not specified
- Libtorch Error: Expected object of type Variable but found type CUDALongType for argument #2 ‘index’
- How to Fix Error return arrays must be of arraytype
- target is multiclass but average=’binary’. please choose another average setting.
- error: (-215:Assertion failed) size.width＞0 && size.height＞0 in function ‘cv::imshow‘
- Win10 ImportError: cannot import name NUMPY_MKL
- Numpy.exp Function Error ‘Float’ object has no attribute ‘exp’
- On error resume next, on error goto 0, err usage
- django Internal server error 500 Modify source code to view print errors
- How to Solve TypeError: type numpy.ndarray doesn’t define __round__ method
- TensorFlow tf.keras.losses .MeanSquaredError
- [Solved] ValueError: the indices for endog and exog are not aligned
- The solution of no module named ‘jinja2. Asyncsupport’
- An error occurs when trying to pipe a python program to CD- sys.excepthook is missing lost sys.stderr
- Axios request failed, get the status code and error information, how to encapsulate the function dealing with the public error code
- Cache penetration, cache breakdown and cache avalanche solutions
- React Hook “useState“ is called in function “xxx“ which is neither a React function component or