_tensor_normalize
get_framework
¶
Get the framework of the input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor |
Tensor
|
The input tensor. |
required |
Returns: framework: Framework which is used to load input data. device: The device on which the method is executed (Eg. cuda, cpu). Only applicable to torch.
Source code in fastestimator/fastestimator/backend/_tensor_normalize.py
get_scaled_data
¶
Get the scaled value of a input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[float, Sequence[float]]
|
The data which needs to be scaled. (eg: 0.4, (0.485, 0.456, 0.406)). |
(0.485, 0.456, 0.406)
|
scale_factor |
float
|
Scale factor which needs to be multipled with input data. |
255.0
|
framework |
str
|
Framework currently method is running in.(Eg: 'np','tf', 'torch'). |
'np'
|
device |
Optional[device]
|
Current device. (eg: 'cpu','cuda'). |
None
|
Returns:
Type | Description |
---|---|
Tensor
|
The scaled value of input data. |
Source code in fastestimator/fastestimator/backend/_tensor_normalize.py
normalize
¶
Compute the normalized value of a tensor
.
This method can be used with Numpy data: python n = np.array([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]) b = fe.backend.tensor_normalize(n, 0.5625, 0.2864, 8.0) # ([[[-1.52752516, -1.0910894 ], [-0.65465364, -0.21821788]], [[ 0.21821788, 0.65465364], [ 1.0910894 , 1.52752516]]]) b = fe.backend.tensor_normalize(n, (0.5, 0.625), (0.2795, 0.2795), 8.0) # [[[-1.34164073, -1.34164073], [-0.44721358, -0.44721358]], [[ 0.44721358, 0.44721358], [ 1.34164073, 1.34164073]]]
This method can be used with TensorFlow tensors: python t = tf.constant([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]) b = fe.backend.tensor_normalize(n, 0.5625, 0.2864, 8.0) # ([[[-1.52752516, -1.0910894 ], [-0.65465364, -0.21821788]], [[ 0.21821788, 0.65465364], [ 1.0910894 , 1.52752516]]]) b = fe.backend.tensor_normalize(n, (0.5, 0.625), (0.2795, 0.2795), 8.0) # [[[-1.34164073, -1.34164073], [-0.44721358, -0.44721358]], [[ 0.44721358, 0.44721358], [ 1.34164073, 1.34164073]]]
This method can be used with PyTorch tensors: python p = torch.tensor([[[1.0, 2.0], [3.0, 4.0]], [[5.0, 6.0], [7.0, 8.0]]]) b = fe.backend.tensor_normalize(n, 0.5625, 0.2864, 8.0) # ([[[-1.52752516, -1.0910894 ], [-0.65465364, -0.21821788]], [[ 0.21821788, 0.65465364], [ 1.0910894 , 1.52752516]]]) b = fe.backend.tensor_normalize(n, (0.5, 0.625), (0.2795, 0.2795), 8.0) # [[[-1.34164073, -1.34164073], [-0.44721358, -0.44721358]], [[ 0.44721358, 0.44721358], [ 1.34164073, 1.34164073]]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor |
Tensor
|
The input 'tensor' value. |
required |
mean |
Union[float, Sequence[float]]
|
The mean which needs to applied(eg: 3.8, (0.485, 0.456, 0.406)). |
(0.485, 0.456, 0.406)
|
std |
Union[float, Sequence[float]]
|
The standard deviation which needs to applied(eg: 3.8, (0.229, 0.224, 0.225)). |
(0.229, 0.224, 0.225)
|
max_pixel_value |
float
|
The max value of the input data(eg: 255, 65025) to be multipled with mean and std to get actual mean and std. To directly use the mean and std provide set max_pixel_value as 1. |
255.0
|
epsilon |
float
|
Default value to be added to std to avoid divide by zero error. |
1e-07
|
Returns:
Type | Description |
---|---|
Tensor
|
The normalized values of |
Raises:
Type | Description |
---|---|
ValueError
|
If |